From 6824d67beb423d51d27b9f297f97c75f6298c183 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Sat, 2 May 2020 18:39:41 +0300 Subject: Fix forms validation snippets. --- site/assets/js/validate-forms.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 site/assets/js/validate-forms.js (limited to 'site/assets/js') 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) + }) +})() -- cgit v1.2.3