Skip to content

Instantly share code, notes, and snippets.

@newhope
Created November 21, 2018 07:41
Show Gist options
  • Select an option

  • Save newhope/2e91afdc9530d5eb9fed8f764b3908c6 to your computer and use it in GitHub Desktop.

Select an option

Save newhope/2e91afdc9530d5eb9fed8f764b3908c6 to your computer and use it in GitHub Desktop.
reportValidity polyfill for IE 10, 11
/**
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;
}
}
@PFight
Copy link
Copy Markdown

PFight commented Jul 29, 2020

Thanks, worked for me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment