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/content/docs/4.3/examples/checkout/form-validation.js')
-rw-r--r--site/content/docs/4.3/examples/checkout/form-validation.js21
1 files changed, 21 insertions, 0 deletions
diff --git a/site/content/docs/4.3/examples/checkout/form-validation.js b/site/content/docs/4.3/examples/checkout/form-validation.js
new file mode 100644
index 0000000000..59291c8b39
--- /dev/null
+++ b/site/content/docs/4.3/examples/checkout/form-validation.js
@@ -0,0 +1,21 @@
+// 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)
+})()