-
-
Save mcshaz/c65040c11e6daffe356cbedb7ec84ce4 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
if (!HTMLFormElement.prototype.requestSubmit) { | |
HTMLFormElement.prototype.requestSubmit = function() { | |
const submitBtn = document.createElement('input'); | |
submitBtn.type = 'submit'; | |
submitBtn.hidden = true; | |
this.appendChild(submitBtn); | |
submitBtn.click(); | |
this.removeChild(submitBtn); | |
}; | |
} | |
if (!HTMLFormElement.prototype.reportValidity) { | |
HTMLFormElement.prototype.reportValidity = function() { | |
if (this.checkValidity()){ | |
return true; | |
} | |
if (this.noValidate){ | |
this.noValidate = false; | |
this.requestSubmit(); | |
this.noValidate = true; | |
} else { | |
this.requestSubmit(); | |
} | |
return false; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great work!
requestSubmit has a "submitter" argument
https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/requestSubmit
This can worn work (not tested):