mirror of
https://github.com/twbs/bootstrap.git
synced 2022-11-09 12:25:43 -05:00
Read validate-forms.js from assets.
This commit is contained in:
parent
6824d67beb
commit
358d637d1c
3 changed files with 10 additions and 24 deletions
|
@ -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
|
||||
|
|
|
@ -47,5 +47,9 @@
|
|||
|
||||
{{ partial "footer" . }}
|
||||
{{ partial "scripts" . }}
|
||||
|
||||
{{ range .Page.Params.extra_js -}}
|
||||
<script{{ with .async }} async{{ end }} src="{{ .src }}"></script>
|
||||
{{- end -}}
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -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) {
|
Loading…
Reference in a new issue