form-validation.js 616 B

1234567891011121314151617181920
  1. // Example starter JavaScript for disabling form submissions if there are invalid fields
  2. (function () {
  3. 'use strict'
  4. // Fetch all the forms we want to apply custom Bootstrap validation styles to
  5. var forms = document.querySelectorAll('.needs-validation')
  6. // Loop over them and prevent submission
  7. Array.prototype.slice.call(forms)
  8. .forEach(function (form) {
  9. form.addEventListener('submit', function (event) {
  10. if (!form.checkValidity()) {
  11. event.preventDefault()
  12. event.stopPropagation()
  13. }
  14. form.classList.add('was-validated')
  15. }, false)
  16. })
  17. })()