()
| 18141 | |
| 18142 | |
| 18143 | var 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 | /** |
nothing calls this directly
no test coverage detected