From: XhmikosR Date: Sat, 2 May 2020 15:39:41 +0000 (+0300) Subject: Fix forms validation snippets. X-Git-Tag: v5.0.0-alpha1~55 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6824d67beb423d51d27b9f297f97c75f6298c183;p=thirdparty%2Fbootstrap.git Fix forms validation snippets. --- 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) + }) +})() diff --git a/site/content/docs/5.0/forms/validation.md b/site/content/docs/5.0/forms/validation.md index 2b8e1b7aa9..c505163624 100644 --- a/site/content/docs/5.0/forms/validation.md +++ b/site/content/docs/5.0/forms/validation.md @@ -96,8 +96,9 @@ Custom feedback styles apply custom colors, borders, focus styles, and backgroun +{{< /example >}} - {{< /example >}} ## Browser defaults