ionic-Material Design , Codecanyon
This commit is contained in:
25
IonicMaterialDesign/www/js/shared/directives.js
Normal file
25
IonicMaterialDesign/www/js/shared/directives.js
Normal file
@@ -0,0 +1,25 @@
|
||||
//Directive numbersOnly :
|
||||
//Use for change input to have ability accept only number.
|
||||
//Example : <input ng-model="contract.age" numbers-only type="tel">
|
||||
//
|
||||
appControllers.directive('numbersOnly', function () {
|
||||
return {
|
||||
require: 'ngModel',
|
||||
link: function (scope, element, attr, ngModelCtrl) {
|
||||
function fromUser(text) {
|
||||
if (text) {
|
||||
var transformedInput = text.replace(/[^0-9]/g, '');
|
||||
|
||||
if (transformedInput !== text) {
|
||||
ngModelCtrl.$setViewValue(transformedInput);
|
||||
ngModelCtrl.$render();
|
||||
}
|
||||
return transformedInput;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
ngModelCtrl.$parsers.push(fromUser);
|
||||
}
|
||||
};
|
||||
});// End Directive numbersOnly.
|
||||
Reference in New Issue
Block a user