()
| 12272 | |
| 12273 | |
| 12274 | var requiredDirective = function() { |
| 12275 | return { |
| 12276 | require: '?ngModel', |
| 12277 | link: function(scope, elm, attr, ctrl) { |
| 12278 | if (!ctrl) return; |
| 12279 | attr.required = true; // force truthy in case we are on non input element |
| 12280 | |
| 12281 | var validator = function(value) { |
| 12282 | if (attr.required && (isEmpty(value) || value === false)) { |
| 12283 | ctrl.$setValidity('required', false); |
| 12284 | return; |
| 12285 | } else { |
| 12286 | ctrl.$setValidity('required', true); |
| 12287 | return value; |
| 12288 | } |
| 12289 | }; |
| 12290 | |
| 12291 | ctrl.$formatters.push(validator); |
| 12292 | ctrl.$parsers.unshift(validator); |
| 12293 | |
| 12294 | attr.$observe('required', function() { |
| 12295 | validator(ctrl.$viewValue); |
| 12296 | }); |
| 12297 | } |
| 12298 | }; |
| 12299 | }; |
| 12300 | |
| 12301 | |
| 12302 | /** |
nothing calls this directly
no test coverage detected