Created
February 5, 2015 19:07
-
-
Save adickson311/f28ce877aaef3fb9d995 to your computer and use it in GitHub Desktop.
Angular directive for preventing user input on a text input box, while allowing them to clear the field with delete.
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
myApp.directive('no-input', function() { | |
return { | |
restrict: 'A', | |
replace: false, | |
link: function(scope, el) { | |
el.on('keydown', function(e){ | |
if(e.keyCode === 8){ | |
el.val(''); | |
el.trigger('change'); | |
} else { | |
e.stopPropagation(); | |
e.preventDefault(); | |
} | |
}); | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment