]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
Read validate-forms.js from assets.
authorXhmikosR <xhmikosr@gmail.com>
Sat, 2 May 2020 15:49:12 +0000 (18:49 +0300)
committerXhmikosR <xhmikosr@gmail.com>
Wed, 3 Jun 2020 12:57:20 +0000 (15:57 +0300)
site/content/docs/5.0/forms/validation.md
site/layouts/_default/docs.html
site/static/docs/5.0/assets/js/validate-forms.js [moved from site/assets/js/validate-forms.js with 95% similarity]

index c5051636249b32ef4d4385f79e052720c8313730..d70507037bc10427444a7b3753570db995ee29a4 100644 (file)
@@ -4,6 +4,9 @@ title: Validation
 description: Provide valuable, actionable feedback to your users with HTML5 form validation, via browser default behaviors or custom styles and JavaScript.
 group: forms
 toc: true
+extra_js:
+  - src: "/docs/5.0/assets/js/validate-forms.js"
+    async: true
 ---
 
 {{< callout warning >}}
@@ -99,26 +102,9 @@ Custom feedback styles apply custom colors, borders, focus styles, and backgroun
 {{< /example >}}
 
 {{< example lang="js" show_preview="false" >}}
-// 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');
-
-  // 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);
-    });
-})();
+{{< js.inline >}}
+{{- readFile (printf "site/static/docs/%s/assets/js/validate-forms.js" .Site.Params.docs_version) -}}
+{{< /js.inline >}}
 {{< /example >}}
 
 ## Browser defaults
index 01890869afcadfd378690c10980e88c1f201236f..2e5bac7fcf01e2cec4f10081ed0903a69ac63751 100644 (file)
@@ -47,5 +47,9 @@
 
     {{ partial "footer" . }}
     {{ partial "scripts" . }}
+
+    {{ range .Page.Params.extra_js -}}
+      <script{{ with .async }} async{{ end }} src="{{ .src }}"></script>
+    {{- end -}}
   </body>
 </html>
similarity index 95%
rename from site/assets/js/validate-forms.js
rename to site/static/docs/5.0/assets/js/validate-forms.js
index b79f63f2dcb0463972db9818bbf126f8a9179ddd..f8fd583de4b1529ca6dc8478f669a70ae29ebe25 100644 (file)
@@ -5,10 +5,6 @@
   // 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) {