From b3082b942543147bbb2bffd78a10ac10c77e1f62 Mon Sep 17 00:00:00 2001 From: Micha Pietsch Date: Fri, 6 Apr 2018 17:33:31 +0200 Subject: [PATCH 1/2] Restore customError property in the ValidityState() polyfill --- src/js/validityState-polyfill.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/js/validityState-polyfill.js b/src/js/validityState-polyfill.js index 7f4de64..d4d6684 100644 --- a/src/js/validityState-polyfill.js +++ b/src/js/validityState-polyfill.js @@ -93,6 +93,11 @@ // Add valid property to validity object checkValidity.valid = valid; + // Assume a custom error if there is a validation message present but all the other checks returned valid + if (checkValidity.valid && field.validationMessage !== '') { + checkValidity.customError = true + } + // Return object return checkValidity; From 8ff808cab8e50cf3cabf6cd29273d78e6c167aa4 Mon Sep 17 00:00:00 2001 From: Micha Pietsch Date: Sat, 7 Apr 2018 14:17:51 +0200 Subject: [PATCH 2/2] Set valid to false if a custom error has been detected --- src/js/validityState-polyfill.js | 3 ++- static/js/validityState-polyfill.js | 6 ++++++ static/js/validityState-polyfill.min.js | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/js/validityState-polyfill.js b/src/js/validityState-polyfill.js index d4d6684..1c90466 100644 --- a/src/js/validityState-polyfill.js +++ b/src/js/validityState-polyfill.js @@ -95,7 +95,8 @@ // Assume a custom error if there is a validation message present but all the other checks returned valid if (checkValidity.valid && field.validationMessage !== '') { - checkValidity.customError = true + checkValidity.customError = true; + checkValidity.valid = false; } // Return object diff --git a/static/js/validityState-polyfill.js b/static/js/validityState-polyfill.js index be41552..a4c3dee 100644 --- a/static/js/validityState-polyfill.js +++ b/static/js/validityState-polyfill.js @@ -100,6 +100,12 @@ // Add valid property to validity object checkValidity.valid = valid; + // Assume a custom error if there is a validation message present but all the other checks returned valid + if (checkValidity.valid && field.validationMessage !== '') { + checkValidity.customError = true; + checkValidity.valid = false; + } + // Return object return checkValidity; diff --git a/static/js/validityState-polyfill.min.js b/static/js/validityState-polyfill.min.js index 699333e..7a86465 100644 --- a/static/js/validityState-polyfill.min.js +++ b/static/js/validityState-polyfill.min.js @@ -1,2 +1,2 @@ /*! validate v1.1.3 | (c) 2018 Chris Ferdinandi | MIT License | http://github.com/cferdinandi/validate */ -!(function(t,e,i){"use strict";var r=(function(){var t=Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,"validity"),e=Object.getOwnPropertyDescriptor(HTMLButtonElement.prototype,"validity"),i=Object.getOwnPropertyDescriptor(HTMLSelectElement.prototype,"validity"),r=Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype,"validity"),x={};return t&&(x.input=t.get),e&&(x.button=e.get),i&&(x.select=i.get),r&&(x.textarea=r.get),x})(),x=function(t){var i=t.getAttribute("type")||t.nodeName.toLowerCase(),x="number"===i||"range"===i,a=t.value.length,n=!0;if("radio"===t.type&&t.name){var u=e.getElementsByName(t.name);if(u.length>0)for(var o=0;o0&&!/^[-+]?(?:\d+|\d*[.,]\d+)$/.test(t.value),patternMismatch:t.hasAttribute("pattern")&&a>0&&!1===new RegExp(t.getAttribute("pattern")).test(t.value),rangeOverflow:t.hasAttribute("max")&&x&&t.value>0&&Number(t.value)>Number(t.getAttribute("max")),rangeUnderflow:t.hasAttribute("min")&&x&&t.value>0&&Number(t.value)0&&a>parseInt(t.getAttribute("maxLength"),10),tooShort:t.hasAttribute("minLength")&&t.getAttribute("minLength")>0&&a>0&&a0&&("email"===i&&!/^([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22))*\x40([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d))*$/.test(t.value)||"url"===i&&!/^(?:(?:https?|HTTPS?|ftp|FTP):\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-zA-Z\u00a1-\uffff0-9]-*)*[a-zA-Z\u00a1-\uffff0-9]+)(?:\.(?:[a-zA-Z\u00a1-\uffff0-9]-*)*[a-zA-Z\u00a1-\uffff0-9]+)*)(?::\d{2,5})?(?:[\/?#]\S*)?$/.test(t.value)),valueMissing:t.hasAttribute("required")&&(("checkbox"===i||"radio"===i)&&!t.hasAttribute("checked")||"select"===i&&(-1===t.selectedIndex||t.options[t.selectedIndex].value.length<1)||"checkbox"!==i&&"radio"!==i&&"select"!==i&&a<1)},f=t.tagName.toLowerCase(),l=f in r?r[f].call(t):{};for(var c in d)d.hasOwnProperty(c)&&(c in l&&l[c]&&(d[c]=!0),d[c]&&(n=!1));return d.valid=n,d};(function(){var t=e.createElement("input");return"validity"in t&&"badInput"in t.validity&&"patternMismatch"in t.validity&&"rangeOverflow"in t.validity&&"rangeUnderflow"in t.validity&&"stepMismatch"in t.validity&&"tooLong"in t.validity&&"tooShort"in t.validity&&"typeMismatch"in t.validity&&"valid"in t.validity&&"valueMissing"in t.validity})()||(Object.defineProperty(HTMLInputElement.prototype,"validity",{get:function(){return x(this)},configurable:!0}),Object.defineProperty(HTMLButtonElement.prototype,"validity",{get:function(){return x(this)},configurable:!0}),Object.defineProperty(HTMLSelectElement.prototype,"validity",{get:function(){return x(this)},configurable:!0}),Object.defineProperty(HTMLTextAreaElement.prototype,"validity",{get:function(){return x(this)},configurable:!0}))})(window,document); \ No newline at end of file +!(function(t,e,i){"use strict";var r=(function(){var t=Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,"validity"),e=Object.getOwnPropertyDescriptor(HTMLButtonElement.prototype,"validity"),i=Object.getOwnPropertyDescriptor(HTMLSelectElement.prototype,"validity"),r=Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype,"validity"),a={};return t&&(a.input=t.get),e&&(a.button=e.get),i&&(a.select=i.get),r&&(a.textarea=r.get),a})(),a=function(t){var i=t.getAttribute("type")||t.nodeName.toLowerCase(),a="number"===i||"range"===i,x=t.value.length,n=!0;if("radio"===t.type&&t.name){var u=e.getElementsByName(t.name);if(u.length>0)for(var o=0;o0&&!/^[-+]?(?:\d+|\d*[.,]\d+)$/.test(t.value),patternMismatch:t.hasAttribute("pattern")&&x>0&&!1===new RegExp(t.getAttribute("pattern")).test(t.value),rangeOverflow:t.hasAttribute("max")&&a&&t.value>0&&Number(t.value)>Number(t.getAttribute("max")),rangeUnderflow:t.hasAttribute("min")&&a&&t.value>0&&Number(t.value)0&&x>parseInt(t.getAttribute("maxLength"),10),tooShort:t.hasAttribute("minLength")&&t.getAttribute("minLength")>0&&x>0&&x0&&("email"===i&&!/^([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22))*\x40([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d))*$/.test(t.value)||"url"===i&&!/^(?:(?:https?|HTTPS?|ftp|FTP):\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-zA-Z\u00a1-\uffff0-9]-*)*[a-zA-Z\u00a1-\uffff0-9]+)(?:\.(?:[a-zA-Z\u00a1-\uffff0-9]-*)*[a-zA-Z\u00a1-\uffff0-9]+)*)(?::\d{2,5})?(?:[\/?#]\S*)?$/.test(t.value)),valueMissing:t.hasAttribute("required")&&(("checkbox"===i||"radio"===i)&&!t.hasAttribute("checked")||"select"===i&&(-1===t.selectedIndex||t.options[t.selectedIndex].value.length<1)||"checkbox"!==i&&"radio"!==i&&"select"!==i&&x<1)},l=t.tagName.toLowerCase(),f=l in r?r[l].call(t):{};for(var c in d)d.hasOwnProperty(c)&&(c in f&&f[c]&&(d[c]=!0),d[c]&&(n=!1));return d.valid=n,d.valid&&""!==t.validationMessage&&(d.customError=!0,d.valid=!1),d};(function(){var t=e.createElement("input");return"validity"in t&&"badInput"in t.validity&&"patternMismatch"in t.validity&&"rangeOverflow"in t.validity&&"rangeUnderflow"in t.validity&&"stepMismatch"in t.validity&&"tooLong"in t.validity&&"tooShort"in t.validity&&"typeMismatch"in t.validity&&"valid"in t.validity&&"valueMissing"in t.validity})()||(Object.defineProperty(HTMLInputElement.prototype,"validity",{get:function(){return a(this)},configurable:!0}),Object.defineProperty(HTMLButtonElement.prototype,"validity",{get:function(){return a(this)},configurable:!0}),Object.defineProperty(HTMLSelectElement.prototype,"validity",{get:function(){return a(this)},configurable:!0}),Object.defineProperty(HTMLTextAreaElement.prototype,"validity",{get:function(){return a(this)},configurable:!0}))})(window,document); \ No newline at end of file