Skip to content

Instantly share code, notes, and snippets.

@rafaell-lycan
Created January 28, 2015 22:28
Show Gist options
  • Save rafaell-lycan/f841018c5118c39d8845 to your computer and use it in GitHub Desktop.
Save rafaell-lycan/f841018c5118c39d8845 to your computer and use it in GitHub Desktop.
AngularJS - Prevent Enter Submit Directive
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.
}
});
};
});
@nitin-rachabathuni
Copy link

awesome.

@raghvpip3
Copy link

super

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment