Using the directive in How to limit input[number] cause a issue.
When in input reached max I want to mark the input(double right click on the input) and then pressing a digit to make it change the entire input don't change it, due to the directive e.preventDefault();
The selection event can be view in:
angular.element(elem).on("select", function(e) {
console.log(e);
});
What is the best way to fix it? The directive:
angular.module('myApp')
.directive('limitTo', limitTo);
function limitTo() {
return {
restrict: "A",
link: function(scope, elem, attrs) {
var limit = parseInt(attrs.limitTo);
angular.element(elem).on("keypress", function(e) {
if (this.value.length == limit){
e.preventDefault();
}
});
}
}
};
And use:
<input type="number" class="form-control form-control-lg" limit-to="6"
ng-model="vm.details.m_inputSMS" placeholder = {{vm.configProprs.kodPlaceHolder}} name ="m_inputSMS" id="m_inputSMS"
ng-model-options="{ updateOn: 'blur' }"required/>