Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/twbs/bootstrap.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
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.js20
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 0000000000..f8fd583de4
--- /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)
+ })
+})()