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:
authorXhmikosR <xhmikosr@gmail.com>2020-05-02 18:39:41 +0300
committerXhmikosR <xhmikosr@gmail.com>2020-06-03 15:57:20 +0300
commit6824d67beb423d51d27b9f297f97c75f6298c183 (patch)
treebb26e31d1aa12339c53ededf74282cdd9ebca08f /site/assets/js
parent08742abda3a7e9717c5c6508537191e68986a24e (diff)
Fix forms validation snippets.
Diffstat (limited to 'site/assets/js')
-rw-r--r--site/assets/js/validate-forms.js24
1 files changed, 24 insertions, 0 deletions
diff --git a/site/assets/js/validate-forms.js b/site/assets/js/validate-forms.js
new file mode 100644
index 0000000000..b79f63f2dc
--- /dev/null
+++ b/site/assets/js/validate-forms.js
@@ -0,0 +1,24 @@
+// 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')
+
+ if (!forms) {
+ return
+ }
+
+ // 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)
+ })
+})()