How to stop form submission in Memberstack when custom validateField function returns false? Answered
Form Submit preventDefault doesn’t seem to work in #127 - Validate Text Inputs v0.1
I’ve cloned the Validate Text Inputs example site with this eventHandler:
if (form) {
form.addEventListener('submit', function(event) {
if (!validateField() && submitButton) {
event.preventDefault();
field.focus();
}
});
}
…and the form still submits even if I use qwert as the zip code. Should the code above not prevent the form from submitting if the zip code is invalid?I’m building my own custom validation based on this but the memberstack.js event listener keeps submitting the form.


Comments
2 comments
Hey Caspar Shelley, can you check if the value of the attribute ms-code-submit-button is set to zip as shown below for the submit button?
Hopefully this should solve the issue.
Yep. That did it! Thanks A J 🙏
Maybe that should be added to the source site? 🤔
Please sign in to leave a comment.