one-way-select: select prompt if value is not a valid option #163
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, a one-way-selects's
prompt
is only selected when the currentvalue
is empty. Whenvalue
is not empty but also not a valid option, the browser initially renders the first passed option instead of the prompt, because none of the options have aselected
attribute and the prompt itself has thedisabled
attribute.All that wouldn't be much of an issue if one doesn't pass invalid options, right? Well, it turns out that if value is an ember data relation,
nothingSelected
evaluates tofalse
because it sees a promise. When the promise resolves tonull
, the first option stays selected becausenothingSelected
is stillfalse
(see #127 and probably also #159).Instead of using
empty
to determinenothingSelected
, I'd propose checking if the passed value is actually a valid option. That doesn't only solve the first issue when an actually invalid option is passed, but also the second issue related to ember-data relations.