Had the same problem, for reasons unknown the prevent default does nothing to the bootstrap 4 form. Here's official code from bs team which has been slightly adjusted.
$(document).ready(function() {
(function() {
'use strict';
window.addEventListener('load', function() {
// Fetch all the forms we want to apply custom Bootstrap validation styles to
var forms = document.getElementsByClassName('notificationForm');
// Loop over them and prevent submission
var validation = Array.prototype.filter.call(forms, function(form) {
form.addEventListener('submit', function(event) {
if (!checkValidity()) {
console.log('did not validate');
event.preventDefault();
event.stopPropagation();
}
form.classList.add('was-validated');
}, false);
});
}, false);
})();
})
Then you need a checkValidity
function which will return true or false depending on your validation.
In case you're validating checkboxes:
Chances are you're validating a group of checkmarks because that's not supported by bs so here's my validation code just in case (this will confirm that at least 1 checkboxes in the regionSelect div have been selected.
function checkValidity() {
var regionsValidation = $('div.regionSelect :checkbox:checked').length;
var categoriesValidation = $('div.categorySelect :checkbox:checked').length;
if( (regionsValidation > 0) && (categoriesValidation > 0)) {
return true;
}
else {
return false;
}
}