forked from angular/angular.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ngModel): revalidate the model when min/max expression values change
As of this fix if the max or min value is changed via scope or by another ngModel then it will trigger the model containing the min/max attributes to revalidate itself. Closes angular#2404
- Loading branch information
Showing
2 changed files
with
49 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1129,15 +1129,30 @@ function numberInputType(scope, element, attr, ctrl, $sniffer, $browser) { | |
}); | ||
|
||
if (attr.min) { | ||
var minVal; | ||
ctrl.$validators.min = function(value) { | ||
return ctrl.$isEmpty(value) || isUndefined(attr.min) || value >= parseFloat(attr.min); | ||
return ctrl.$isEmpty(value) || isUndefined(minVal) || value >= minVal; | ||
}; | ||
|
||
val = isDefined(val) && parseFloat(val, 10); | ||
minVal = isNaN(val) ? undefined : val; | ||
// TODO(matsko): implement validateLater to reduce number of validations | ||
ctrl.$validate(); | ||
}); | ||
} | ||
|
||
if (attr.max) { | ||
var maxVal; | ||
ctrl.$validators.max = function(value) { | ||
return ctrl.$isEmpty(value) || isUndefined(attr.max) || value <= parseFloat(attr.max); | ||
return ctrl.$isEmpty(value) || isUndefined(maxVal) || value <= maxVal; | ||
}; | ||
|
||
attr.$observe('max', function(val) { | ||
val = isDefined(val) && parseFloat(val, 10); | ||
maxVal = isNaN(val) ? undefined : val; | ||
// TODO(matsko): implement validateLater to reduce number of validations | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
matsko
Author
Owner
|
||
ctrl.$validate(); | ||
}); | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
what if we instead just set the validation css classes in post-digest that way revalidating the model would become cheap?