Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

fix(required): correctly validate when required #16846

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/content/guide/di.ngdoc
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ Here is an example of using the injector service:
var myModule = angular.module('myModule', []);
```

Notice that `myModule` depends upon no other modules as the second parameter is an empty array.
Teach the injector how to build a `greeter` service. Notice that `greeter` is dependent on the
`$window` service. The `greeter` service is an object that contains a `greet` method.

Expand Down
6 changes: 4 additions & 2 deletions src/ng/directive/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,11 @@ var requiredDirective = ['$parse', function($parse) {
require: '?ngModel',
link: function(scope, elm, attr, ctrl) {
if (!ctrl) return;
var value = attr.required || $parse(attr.ngRequired)(scope);
var value = 'required' in attr || $parse(attr.ngRequired)(scope);

attr.required = true; // force truthy in case we are on non input element
if (!attr.ngRequired) {
attr.required = true;
} // force truthy in case we are on non input element

ctrl.$validators.required = function(modelValue, viewValue) {
return !value || !ctrl.$isEmpty(viewValue);
Expand Down