MCPcopy Index your code
hub / github.com/angular-ui/ui-router / requiredDirective

Function requiredDirective

test/angular/1.2/angular.js:18143–18168  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

18141
18142
18143var requiredDirective = function() {
18144 return {
18145 require: '?ngModel',
18146 link: function(scope, elm, attr, ctrl) {
18147 if (!ctrl) return;
18148 attr.required = true; // force truthy in case we are on non input element
18149
18150 var validator = function(value) {
18151 if (attr.required && ctrl.$isEmpty(value)) {
18152 ctrl.$setValidity('required', false);
18153 return;
18154 } else {
18155 ctrl.$setValidity('required', true);
18156 return value;
18157 }
18158 };
18159
18160 ctrl.$formatters.push(validator);
18161 ctrl.$parsers.unshift(validator);
18162
18163 attr.$observe('required', function() {
18164 validator(ctrl.$viewValue);
18165 });
18166 }
18167 };
18168};
18169
18170
18171/**

Callers

nothing calls this directly

Calls 1

validatorFunction · 0.85

Tested by

no test coverage detected