This repository was archived by the owner on Oct 2, 2019. It is now read-only.
feat(choices): add null option support #699
Closed
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.
Needed this feature so decided to implement it. I toyed with a few different solutions and boiled it down to this (doesn't look like much, but it took me quite a while to get to this).
This solution requires that the "null" option is a typical item present in the array so that we have flexibility in filtering and displaying it without having to write a bunch of conditional statements. We then use the "null-option" directive on the "ui-select-choices" element to mark our null option. When the option is selected, the model is set to null (and vice versa).
An additional helper option is included - "loose-null" - which tells ui-select to treat undefined and null as the same. In this case, if the model value is undefined, the null option will still be displayed. Just add
"loose-null" on the "ui-select-choices" element.
See http://plnkr.co/edit/7nmBRicsmH33E55sSomz?p=preview.
Happy to discuss implementation specifics, thought I'd open this PR to get the ball rolling. Yet to write unit tests... Could anyone help with this?