--- /dev/null
+// 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)
+ })
+})()
<button class="btn btn-primary" type="submit">Submit form</button>
</div>
</form>
+{{< /example >}}
-<script>
+{{< example lang="js" show_preview="false" >}}
// Example starter JavaScript for disabling form submissions if there are invalid fields
(function () {
'use strict';
}, false);
});
})();
-</script>
{{< /example >}}
## Browser defaults