Skip to content

Instantly share code, notes, and snippets.

@adickson311
Created February 5, 2015 19:07
Show Gist options
  • Save adickson311/f28ce877aaef3fb9d995 to your computer and use it in GitHub Desktop.
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.
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