aboutsummaryrefslogtreecommitdiff
path: root/site/docs/4.4/examples/checkout/form-validation.js
diff options
context:
space:
mode:
authorXhmikosR <[email protected]>2019-11-26 19:12:00 +0200
committerGitHub <[email protected]>2019-11-26 19:12:00 +0200
commit593574d510050dc2d5eeafe70a58ae182f020480 (patch)
tree043a163d6c712121ca0fe1f34c419ab592b03185 /site/docs/4.4/examples/checkout/form-validation.js
parentd61bba584f89c7df0d780a9ff214a58f7b58cb94 (diff)
downloadbootstrap-4.4.0.tar.xz
bootstrap-4.4.0.zip
Release v4.4.0 (#29735)v4.4.0
Diffstat (limited to 'site/docs/4.4/examples/checkout/form-validation.js')
-rw-r--r--site/docs/4.4/examples/checkout/form-validation.js20
1 files changed, 20 insertions, 0 deletions
diff --git a/site/docs/4.4/examples/checkout/form-validation.js b/site/docs/4.4/examples/checkout/form-validation.js
new file mode 100644
index 000000000..280849408
--- /dev/null
+++ b/site/docs/4.4/examples/checkout/form-validation.js
@@ -0,0 +1,20 @@
+// Example starter JavaScript for disabling form submissions if there are invalid fields
+(function () {
+ 'use strict'
+
+ window.addEventListener('load', function () {
+ // Fetch all the forms we want to apply custom Bootstrap validation styles to
+ var forms = document.getElementsByClassName('needs-validation')
+
+ // Loop over them and prevent submission
+ Array.prototype.filter.call(forms, function (form) {
+ form.addEventListener('submit', function (event) {
+ if (form.checkValidity() === false) {
+ event.preventDefault()
+ event.stopPropagation()
+ }
+ form.classList.add('was-validated')
+ }, false)
+ })
+ }, false)
+}())