How can I call a function that fires only after an interger value is typed into an input field? (So any number 0-9)
Col <input type="text" value='tiledata.col' ng-model="tiledata.col" class="input-col" id="aeS-Col" ng-click="vm.setInputCol()">
How can I call a function that fires only after an interger value is typed into an input field? (So any number 0-9)
Col <input type="text" value='tiledata.col' ng-model="tiledata.col" class="input-col" id="aeS-Col" ng-click="vm.setInputCol()">
yes ..we can do by
document.getElementById('aeS-Col').onkeydown = function(e){};
codepen url for reference http://codepen.io/nagasai/pen/zBrLEj
Well event can be fired on change, but does not depend on the value, but you can check within the onchange event handler function to check for the entered character :
element.addEventListener("keydown", function(event) {
var character = keysight(event).char
//Check if this is a number (eg: using regex)
//Call function required.
}
In your code change the ng-click to ng-click=vm.setInputCol(event)
and then in the function do the above check and return if not true is one way of doing it.
Since it seems you are using angular, you can check like this as well.
$scope.vm.setInputCol = function(){
if(typeof $scope.tiledata.col === typeof 1)
{
alert("Do your stuff");
}
else
{
return;
};
};
The .onkeypress() would be the preferred method for doing this. onkeypress vs onkeydown
In theory, the keydown and keyup events represent keys being pressed or released, while the keypress event represents a character being typed. The implementation of the theory is not same in all browsers.
So example (in jQuery):
$( "#aeS-Col" ).onkeypress( function( key )
{
if( key.test( /[0-9]/ ) )
callSuperFunction();
}