I have the following code.
<input ng-keypress="onlyNumbers($event)" min="0" type="number" step="1" ng-pattern="/^[0-9]{1,8}$/" ng-model="... >
Now it accepts only numerical values. I want null values to be accepted too. Since there are null values in database, i want it to reflect in the UI. currently i get [Object][Object] at the input for null value.
$scope.onlyNumbers = function(event){
var keys = {
'up': 38,
// Other key codes
...
'9':57
};
for(var index in keys) {
if (!keys.hasOwnProperty(index)) continue;
if (event.charCode==keys[index]||event.keyCode==keys[index]) {
return; //default event
}
}
event.preventDefault();
};
Can anyone let me know how to make it work ?
I have the following code.
<input ng-keypress="onlyNumbers($event)" min="0" type="number" step="1" ng-pattern="/^[0-9]{1,8}$/" ng-model="... >
Now it accepts only numerical values. I want null values to be accepted too. Since there are null values in database, i want it to reflect in the UI. currently i get [Object][Object] at the input for null value.
$scope.onlyNumbers = function(event){
var keys = {
'up': 38,
// Other key codes
...
'9':57
};
for(var index in keys) {
if (!keys.hasOwnProperty(index)) continue;
if (event.charCode==keys[index]||event.keyCode==keys[index]) {
return; //default event
}
}
event.preventDefault();
};
Can anyone let me know how to make it work ?
Share Improve this question edited Nov 23, 2022 at 5:13 Yevgeniy Afanasyev 41.5k30 gold badges186 silver badges207 bronze badges asked Jun 7, 2016 at 19:14 PatrickPatrick 4,3186 gold badges22 silver badges33 bronze badges1 Answer
Reset to default 5What if you remove the min
attribute and modified the ng-pattern to check for an empty input?
<input ng-keypress="onlyNumbers($event)" type="number" step="1" ng-pattern="/^[0-9]{1,8}$|^$/" ng-model="... >
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744843715a4596709.html
评论列表(0条)