Created
November 21, 2018 07:41
-
-
Save newhope/2e91afdc9530d5eb9fed8f764b3908c6 to your computer and use it in GitHub Desktop.
reportValidity polyfill for IE 10, 11
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
Only work if your form has a submit button | |
*/ | |
if ( ! HTMLFormElement.prototype.reportValidity) { | |
HTMLFormElement.prototype.reportValidity = function () { | |
var validity = this.checkValidity(); | |
if ( ! validity) { | |
var submitButtons = this.querySelectorAll("button, input[type=submit]"); | |
for (var i = 0; i < submitButtons.length; i++) { | |
if (submitButtons[i].type === "submit") { | |
submitButtons[i].click(); | |
return validity; | |
} | |
} | |
} | |
return validity; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
another shot - doesn't matter if a form has multiple submit buttons, does matter if a form has a nosubmit attribute
https://gist.github.com/mcshaz/c65040c11e6daffe356cbedb7ec84ce4