1
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-08-21 20:55:50 +02:00

Fix forms validation snippets.

This commit is contained in:
XhmikosR
2020-05-02 18:39:41 +03:00
parent 08742abda3
commit 6824d67beb
2 changed files with 26 additions and 2 deletions

View File

@@ -0,0 +1,24 @@
// Example starter JavaScript for disabling form submissions if there are invalid fields
(function () {
'use strict'
// Fetch all the forms we want to apply custom Bootstrap validation styles to
var forms = document.querySelectorAll('.needs-validation')
if (!forms) {
return
}
// Loop over them and prevent submission
Array.prototype.slice.call(forms)
.forEach(function (form) {
form.addEventListener('submit', function (event) {
if (!form.checkValidity()) {
event.preventDefault()
event.stopPropagation()
}
form.classList.add('was-validated')
}, false)
})
})()