Created
April 20, 2018 17:51
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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