Created
January 28, 2015 22:28
-
-
Save rafaell-lycan/f841018c5118c39d8845 to your computer and use it in GitHub Desktop.
AngularJS - Prevent Enter Submit Directive
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
angular.module('app',[]) | |
.directive('preventEnterSubmit', function () { | |
return function (scope, el, attrs) { | |
el.bind('keydown', function (event) { | |
if (13 == event.which) { | |
event.preventDefault(); // Doesn't work at all | |
window.stop(); // Works in all browsers but IE... | |
document.execCommand('Stop'); // Works in IE | |
return false; // Don't even know why it's here. Does nothing. | |
} | |
}); | |
}; | |
}); |
thanx a lot man, saved my 📦
awesome.
super
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
a little bit late fot you but, here's an example
<input type="text" name="title" ng-model="form.title" prevent-enter-submit>
<form name="form" accept-charset="utf-8" prevent-enter-submit>