Skip to content

Instantly share code, notes, and snippets.

@michalczukm
Created May 15, 2015 23:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michalczukm/c35f4536a55dbb941c42 to your computer and use it in GitHub Desktop.
Save michalczukm/c35f4536a55dbb941c42 to your computer and use it in GitHub Desktop.
JS prevent submit form on enter
// usage
FormUtils.preventSubmitOnEnter($('#add_segment_form'));
FormUtils = {
init: function(){},
preventSubmitOnEnter: function($form){
$form.on("keyup keypress", function(e) {
var code = e.keyCode || e.which;
if (code == 13) {
e.preventDefault();
return false;
}
});
},
clearSelected: function(selector){
$(selector).find("option").prop("selected", false);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment