MCPcopy
hub / github.com/angular-ui/ui-grid / patternDirective

Function patternDirective

lib/test/angular/1.6.7/angular.js:33818–33847  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

33816 * </example>
33817 */
33818var patternDirective = function() {
33819 return {
33820 restrict: 'A',
33821 require: '?ngModel',
33822 link: function(scope, elm, attr, ctrl) {
33823 if (!ctrl) return;
33824
33825 var regexp, patternExp = attr.ngPattern || attr.pattern;
33826 attr.$observe('pattern', function(regex) {
33827 if (isString(regex) && regex.length > 0) {
33828 regex = new RegExp('^' + regex + '$');
33829 }
33830
33831 if (regex && !regex.test) {
33832 throw minErr('ngPattern')('noregexp',
33833 'Expected {0} to be a RegExp but was {1}. Element: {2}', patternExp,
33834 regex, startingTag(elm));
33835 }
33836
33837 regexp = regex || undefined;
33838 ctrl.$validate();
33839 });
33840
33841 ctrl.$validators.pattern = function(modelValue, viewValue) {
33842 // HTML5 pattern constraint validates the input value, so we validate the viewValue
33843 return ctrl.$isEmpty(viewValue) || isUndefined(regexp) || regexp.test(viewValue);
33844 };
33845 }
33846 };
33847};
33848
33849/**
33850 * @ngdoc directive

Callers

nothing calls this directly

Calls 4

isStringFunction · 0.70
minErrFunction · 0.70
startingTagFunction · 0.70
isUndefinedFunction · 0.70

Tested by

no test coverage detected