Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.

feat(choices): add null option support #699

Closed
wants to merge 1 commit into from
Closed

feat(choices): add null option support #699

wants to merge 1 commit into from

Conversation

dlukez
Copy link

@dlukez dlukez commented Feb 25, 2015

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?

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.

Yet to write unit tests... Could anyone help with this?

Closes #302
@dlukez
Copy link
Author

dlukez commented Feb 25, 2015

Mm, may not have been as relevant to #302 as I thought after having another read. May take another look at this at some point. If we want to include the null-option in the filtering things might be tough since the filtering happens outside of ui-select itself.

@dimirc
Copy link
Contributor

dimirc commented Feb 26, 2015

If nullOption is used, then placeholder won't work or when will it be shown?

@dlukez
Copy link
Author

dlukez commented Feb 26, 2015

The placeholder would be shown if "loose-null" isn't used and the value is undefined. I agree that this relationship between placeholder/null-option should probably be further thought out.

@dlukez
Copy link
Author

dlukez commented Feb 26, 2015

Gonna close this for now to make sure it's not accidentally merged before it's ready. A discussion is still on going in #302 on this

@dlukez dlukez closed this Feb 26, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants