This repository was archived by the owner on Sep 5, 2024. It is now read-only.
fix(select): ngModel validator should use option hashkeys. #8763
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently when using
required
on the select, is adding the required validator to the ngModelCtrl.The required validator is checking the
$viewValue
by using the$isEmpty
function, which is overwrittenby the select component.
$isEmpty
normally checks just for truthy values, but our custom$isEmpty
function checks the value for being a registered option.This does not work, because we are just trying to find the value in the options object.
Once the the value is also an object, we are not able to find the option (which is wrong). All options inside of the variable are stored within their
associated hashkey.
That's why we have to retrieve the hashkey of the current value. This is also required for ngModel's with a
trackBy
option.Once an option is set to the ngModel, before the actual
md-option
directive is registered, the required validator will be set tofalse
.We have to trigger a new validation, when the option, which is currently the $modelValue, has been registered.
Fixes #8666.
Please review @topherfangio @crisbeto