diff options
| author | XhmikosR <[email protected]> | 2021-08-04 18:41:51 +0300 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-08-04 18:41:51 +0300 |
| commit | f20fece3a8cdd0e76a42c2737524b7652bf54d26 (patch) | |
| tree | 83e62cc954b17a8bc21cd5975bfd88da721793d1 /site/static/docs/5.1/assets/js/validate-forms.js | |
| parent | 7fcc2f4d526ff774a0a7de6b624a607e5ba47fb9 (diff) | |
| download | bootstrap-5.1.0.tar.xz bootstrap-5.1.0.zip | |
Prepare v5.1.0. (#34674)v5.1.0
Diffstat (limited to 'site/static/docs/5.1/assets/js/validate-forms.js')
| -rw-r--r-- | site/static/docs/5.1/assets/js/validate-forms.js | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/site/static/docs/5.1/assets/js/validate-forms.js b/site/static/docs/5.1/assets/js/validate-forms.js new file mode 100644 index 000000000..f8fd583de --- /dev/null +++ b/site/static/docs/5.1/assets/js/validate-forms.js @@ -0,0 +1,20 @@ +// 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') + + // 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) + }) +})() |
