0
0
mirror of https://github.com/twbs/bootstrap.git synced 2024-12-04 16:24:22 +01:00
Bootstrap/site/static/docs/5.3/assets/js/validate-forms.js

20 lines
559 B
JavaScript
Raw Normal View History

2020-05-02 17:39:41 +02:00
// Example starter JavaScript for disabling form submissions if there are invalid fields
(() => {
2020-05-02 17:39:41 +02:00
'use strict'
// Fetch all the forms we want to apply custom Bootstrap validation styles to
const forms = document.querySelectorAll('.needs-validation')
2020-05-02 17:39:41 +02:00
// Loop over them and prevent submission
Array.from(forms).forEach(form => {
form.addEventListener('submit', event => {
if (!form.checkValidity()) {
event.preventDefault()
event.stopPropagation()
}
2020-05-02 17:39:41 +02:00
form.classList.add('was-validated')
}, false)
})
2020-05-02 17:39:41 +02:00
})()