Add event listener for Bootstrap form validation

This commit is contained in:
billz 2021-03-07 13:19:56 +00:00
parent 55e94adb2b
commit 96bd34f07f
1 changed files with 16 additions and 0 deletions

View File

@ -361,6 +361,22 @@ $('.wg-keygen').click(function(){
})
})
// Event listener for Bootstrap's form validation
window.addEventListener('load', function() {
// Fetch all the forms we want to apply custom Bootstrap validation styles to
var forms = document.getElementsByClassName('needs-validation');
// Loop over them and prevent submission
var validation = Array.prototype.filter.call(forms, function(form) {
form.addEventListener('submit', function(event) {
if (form.checkValidity() === false) {
event.preventDefault();
event.stopPropagation();
}
form.classList.add('was-validated');
}, false);
});
}, false);
// Static Array method
Array.range = (start, end) => Array.from({length: (end - start)}, (v, k) => k + start);