Sha256: 83e2334a8989645ecfafab43a439a0327c96b4005d4b9433cc39c761b06fb84b

Contents?: true

Size: 1.27 KB

Versions: 8

Compression:

Stored size: 1.27 KB

Contents

/*
 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());
          });
        });
      }
    };
  }
]);

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
active_record_survey_api-0.0.19 spec/test_app/vendor/assets/bower_components/angular-ui/modules/directives/mask/mask.js
active_record_survey_api-0.0.18 spec/test_app/vendor/assets/bower_components/angular-ui/modules/directives/mask/mask.js
active_record_survey_api-0.0.17 spec/test_app/vendor/assets/bower_components/angular-ui/modules/directives/mask/mask.js
active_record_survey_api-0.0.14 spec/test_app/vendor/assets/bower_components/angular-ui/modules/directives/mask/mask.js
active_record_survey_api-0.0.12 spec/test_app/vendor/assets/bower_components/angular-ui/modules/directives/mask/mask.js
active_record_survey_api-0.0.11 spec/test_app/vendor/assets/bower_components/angular-ui/modules/directives/mask/mask.js
active_record_survey_api-0.0.7 spec/test_app/vendor/assets/bower_components/angular-ui/modules/directives/mask/mask.js
active_record_survey_api-0.0.6 spec/test_app/vendor/assets/bower_components/angular-ui/modules/directives/mask/mask.js