diff options
Diffstat (limited to 'js/vendor/angular-ui/modules/directives/mask/mask.js')
-rw-r--r-- | js/vendor/angular-ui/modules/directives/mask/mask.js | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/js/vendor/angular-ui/modules/directives/mask/mask.js b/js/vendor/angular-ui/modules/directives/mask/mask.js new file mode 100644 index 000000000..be970ba31 --- /dev/null +++ b/js/vendor/angular-ui/modules/directives/mask/mask.js @@ -0,0 +1,38 @@ +/* + Attaches jquery-ui input mask onto input element + */ +angular.module('ui.directives').directive('uiMask', [ + function () { + return { + require:'ngModel', + link:function ($scope, element, attrs, controller) { + + /* We override the render method to run the jQuery mask plugin + */ + controller.$render = function () { + var value = controller.$viewValue || ''; + element.val(value); + element.mask($scope.$eval(attrs.uiMask)); + }; + + /* Add a parser that extracts the masked value into the model but only if the mask is valid + */ + controller.$parsers.push(function (value) { + //the second check (or) is only needed due to the fact that element.isMaskValid() will keep returning undefined + //until there was at least one key event + var isValid = element.isMaskValid() || angular.isUndefined(element.isMaskValid()) && element.val().length>0; + controller.$setValidity('mask', isValid); + return isValid ? value : undefined; + }); + + /* When keyup, update the view value + */ + element.bind('keyup', function () { + $scope.$apply(function () { + controller.$setViewValue(element.mask()); + }); + }); + } + }; + } +]); |