Add option to apply mask on the fly
See original GitHub issueHi, thanks for the plugin. I am adding this issue because it would be really appreciated if you add an option to allow apply masks on the fly. i am trying to set some common masks shortcuts using a directive, but i can’t get it to work. I’m fairly new to angularjs, and any help would be greatly appreciated.
here is the code of my custom directive to alter input in the dom, to add the ngMask plugin attributes:
angular.module(‘myApp’, [‘ngMask’]) .directive(‘applyMask’, function () { return { restrict: ‘A’, controller: function ($element) { var maskType = $element[0].attributes[‘apply-mask’].value; switch (maskType) { case ‘phone’: { $element.attr(‘mask’, ‘(ddd) - ddd-dddd’) .attr(‘mask-restrict’, ‘reject’) .attr(‘mask-clean’, ‘true’); } break;
}
},
compile: function (element, attributes) {
return {
pre: function (scope, element, attributes, controller, transcludeFn) {
var maskType = attributes["applyMask"];
switch (maskType) {
case 'phone': {
element.attr('mask', '(ddd) - ddd-dddd')
.attr('mask-restrict', 'reject')
.attr('mask-clean', 'true');
} break;
}
},
post: function (scope, element, attributes, controller, transcludeFn) {
var maskType = attributes["applyMask"];
switch (maskType) {
case 'phone': {
element.attr('mask', '(ddd) - ddd-dddd')
.attr('mask-restrict', 'reject')
.attr('mask-clean', 'true');
} break;
}
}
}
}
}
});
and here it is the way i am trying to apply to an input element:
Issue Analytics
- State:
- Created 8 years ago
- Comments:11 (2 by maintainers)
Top GitHub Comments
+1 Anything happening with this request? Using a variable to bind to seems like a common scenario.
+1