Skip to content

Instantly share code, notes, and snippets.

@stevewithington
Created April 20, 2018 17:51
Show Gist options
  • Save stevewithington/30c4336016e7885a4d25acebe10fef42 to your computer and use it in GitHub Desktop.
Save stevewithington/30c4336016e7885a4d25acebe10fef42 to your computer and use it in GitHub Desktop.
Mura: How to add a validation method to a custom form that doesn't override Mura's async form submission
<script>
Mura(function(m) {
window.customFormValidation = function(theform) {
// example validation
if (theform.somefield.value === '') {
alert('Please enter a value in somefield');
theform.somefield.focus();
return false;
}
// let Mura process the form now
Mura.submitForm(theform);
return false;
}
});
</script>
<form method="post" name="someform" onsubmit="window.customFormValidation(this);return false;" novalidate>
<input name="somefield" />
<input name="submit" type="submit" value="Submit" />
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment