Hmm yes, you’re right. In that case, I would attach a click event to the button, prevent the form from submitting, do validation and then submit the form if that passes:
const btn = document.querySelector('.hs-button.primary.large');
const form = document.querySelector('[selectors for your form]');
function validation(){
// your validation test, probably something that returns a boolean
return true
}
btn.addEventListener('click', e => {
e.preventDefault();
if (validation()) {
console.log('validation passed');
form.submit();
} else {
console.log('validation failed');
return false;
}
});
I tested this out and it will prevent form submission.