I have a following piece of code on a few pages, and I'll need it on even more:
$('.editable-textbox').live('keypress', function(e) {
if (e.keyCode == 13) {
$(this).blur();
return false;
}
return true;
}).live('keyup', function(e) {
if (e.keyCode == 13) {
$(this).blur();
return false;
}
return true;
});
There're a few drawbacks of it:
- the code doesn't imply what it does. What it does is: prevents form submittion when enter is hit on control with
.editable-textboxclass + control is blurred - of course code duplication
I just wonder: is there a way to refactor it to have something like this:
$('.editable-textbox').supressFormSubmitOnEnter();
with jQuery.