-
Notifications
You must be signed in to change notification settings - Fork 27.4k
feat(ngModel): provide ng-empty and ng-not-empty CSS classes #12848
Conversation
f529a4b
to
2b046f9
Compare
I wonder if people will ask for this to be propagated to a parent |
I was trying not to mention that :-P |
For the original use case, you would then use |
@@ -316,6 +318,17 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$ | |||
return isUndefined(value) || value === '' || value === null || value !== value; | |||
}; | |||
|
|||
this.$$updateEmptyClasses = function(value) { | |||
if (this.$isEmpty(value)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this
be ctrl
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't really matter because we have control over when it is called but I agree it is probably better for consistency.
@@ -316,6 +318,17 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$ | |||
return isUndefined(value) || value === '' || value === null || value !== value; | |||
}; | |||
|
|||
this.$$updateEmptyClasses = function(value) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be simplified by always using ctrl.$viewValue instead of passing it as an arg. It should only be the viewValue anyway. You'll have to change the order on line https://github.com/angular/angular.js/pull/12848/files#diff-ae1963e24d6328c3aa019c0c1b9f4432R851 though, because otherwise it'll use the old viewValue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually it would have to use $$lastCommittedViewValue
and we would have to change the order as you suggest. I am not that keen on doing this though as I don't feel that not passing in an argument makes it that much simpler.
Regarding my question
because only ng-empty doesn't work if I understood the issue correctly. |
@Narretz: Yes, you would use a combination of the CSS classes for the original use case, but this seemed reasonable and intuitive to me. |
Thanks for the review @Narretz. |
Yep, feel free to merge!
|
It is no longer appropriate to test this here as $animate takes care of queueing up CSS class changes into a single update.
If the `$viewValue` is empty then the `ng-empty` CSS class is applied to the input. Conversely, if it is not empty the `ng-not-empty` CSS class is applied. Emptiness is ascertained by calling `NgModelController.$isEmpty()` Closes angular#10050 Closes angular#12848
9d6087d
to
630280c
Compare
I believe that this feature should be enough to fix #10050