MCPcopy Index your code
hub / github.com/angular-ui/ui-grid / patternDirective

Function patternDirective

lib/test/angular/1.5.0/angular.js:30067–30096  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

30065 * </example>
30066 */
30067var patternDirective = function() {
30068 return {
30069 restrict: 'A',
30070 require: '?ngModel',
30071 link: function(scope, elm, attr, ctrl) {
30072 if (!ctrl) return;
30073
30074 var regexp, patternExp = attr.ngPattern || attr.pattern;
30075 attr.$observe('pattern', function(regex) {
30076 if (isString(regex) && regex.length > 0) {
30077 regex = new RegExp('^' + regex + '$');
30078 }
30079
30080 if (regex && !regex.test) {
30081 throw minErr('ngPattern')('noregexp',
30082 'Expected {0} to be a RegExp but was {1}. Element: {2}', patternExp,
30083 regex, startingTag(elm));
30084 }
30085
30086 regexp = regex || undefined;
30087 ctrl.$validate();
30088 });
30089
30090 ctrl.$validators.pattern = function(modelValue, viewValue) {
30091 // HTML5 pattern constraint validates the input value, so we validate the viewValue
30092 return ctrl.$isEmpty(viewValue) || isUndefined(regexp) || regexp.test(viewValue);
30093 };
30094 }
30095 };
30096};
30097
30098/**
30099 * @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