ui-select icon indicating copy to clipboard operation
ui-select copied to clipboard

Provide option to add no-value choice

Open just-boris opened this issue 12 years ago • 59 comments

Angular.js select directive have a convenient way to define null-value option. If you put <option> tag without value inside <select>, it will be treated as null-option which sets model value to null. It is useful sometimes to provide user ability to reset selected value. Now I have to implicitly add that item to other choices in repeat.

$scope.persons = [{"id": null, "name": "No person"}].concat(otherPersons)
<ui-select ng-model="form.person">
    <ui-select-match placeholder="Select person...">{{$select.selected.name}}</ui-select-match>
    <ui-select-choices repeat="person.id as person in persons">{{person.title}}</ui-select-choices>
</ui-select>

I don't want to do it and it would be good if you will have an option for provide this option through html, for example

<ui-select ng-model="form.person">
    <ui-select-match placeholder="Select person...">{{$select.selected.name}}</ui-select-match>
    <ui-select-null-choice>No person</ui-select-null-choice>
    <ui-select-choices repeat="person.id as person in persons">{{person.title}}</ui-select-choices>
</ui-select>

It is similar to select directive logic and looks good for me. What do you think?

just-boris avatar Oct 14 '14 10:10 just-boris

I agree, and in addition I would also like an "x" button, even when in single select mode to reset the ui-select to this "empty choice". Is there currently any way to have the "x" button in single select mode?

erobwen avatar Oct 15 '14 11:10 erobwen

@erobwen you can put clear button inside <ui-select-match />

just-boris avatar Oct 15 '14 12:10 just-boris

just-boris: Is there an example of how to do it?

erobwen avatar Oct 15 '14 13:10 erobwen

Why not just use clear? https://github.com/angular-ui/ui-select/pull/287

amcdnl avatar Oct 15 '14 20:10 amcdnl

@amcdnl it could be helpful, but it is not quite suitable for me. My use-case of ui-select is a filter of persons. So, user can select some person or select option "Any person" that's means null It couldn't be solved by the clear button, because user would see a placeholder "Select person..." instead of actual meaning "Any person"

Here is a plunkr of that what I want to get

just-boris avatar Oct 16 '14 07:10 just-boris

amcdnl: I try to use it with the bootstrap theme (downloaded latest ui-select with bower). Maybe there is something wrong with my setup, or is it not compatible with the bootstrap theme? But I get no result from using "allow-clear", no clear button appears?

Another wierd thing is that "propsFilter" from your plunker does not work on my version, I have to type "filter" and only filter on one single property for it to show any items in the dropdown.

erobwen avatar Oct 16 '14 07:10 erobwen

@erobwen - Just to clarify, in their plunker they have implemented the propsFilter in their controller. So if you didn't also implement it, then you wouldn't be able to use it. 'filter' is a default filter provided by ng.

jstoneky avatar Oct 31 '14 13:10 jstoneky

Does it need to be another directive? Personally, I'd like to move away from so many directives and attributes and more towards a configuration object that could be passed in. This would make it more dynamic.

lifehackett avatar Oct 31 '14 18:10 lifehackett

@ken4z where you will store that configuration object? When you are using a directive, you can configure your controls just in markup and you can see configuration right in that place where it will be used. So I vote for the declarative way through directives

just-boris avatar Oct 31 '14 20:10 just-boris

There would still be a directive, but the null value display name could just be passed in. <ui-select-choices null-label="No person"></ui-select-choices>

Instead of making it an additional attribute though, I'd rather have something like

<ui-select ng-model="form.person" options="options">
    <ui-select-choices repeat="person.id as person in persons">{{person.title}}</ui-select-choices>
</ui-select>

where options is something like

options = {
  multiple: false,
  placeholder: 'Select person...',
  nullLabel: 'No person',
  searchEnabled: false,
  selectedDisplayProperty: 'name'
}

We have a lot of selects that are fairly similar so I'd like to have a wrapper for ui-select that encompasses this commonality with data to change the behavior, changing the properties of an object is easier than adding/removing/manipulating html. But perhaps there is a way you achieve this that I am not aware of.

lifehackett avatar Oct 31 '14 21:10 lifehackett

+1 For this feature (in combination with bootstrap theme).

FFelling avatar Dec 04 '14 11:12 FFelling

+1

shlensky avatar Dec 11 '14 12:12 shlensky

+1

antonchaika avatar Dec 11 '14 13:12 antonchaika

+1

ErikSvedin avatar Dec 12 '14 14:12 ErikSvedin

+1

kjim avatar Dec 18 '14 02:12 kjim

+1

alonn24 avatar Dec 24 '14 13:12 alonn24

+1

jasny avatar Jan 16 '15 10:01 jasny

+1

fantasia949 avatar Jan 26 '15 07:01 fantasia949

+1

Anton-Nikishkin avatar Jan 26 '15 13:01 Anton-Nikishkin

+1

akirich avatar Jan 27 '15 21:01 akirich