Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not go back to nothing selected state #161

Open
vladlep opened this issue Apr 20, 2017 · 3 comments
Open

Can not go back to nothing selected state #161

vladlep opened this issue Apr 20, 2017 · 3 comments

Comments

@vladlep
Copy link

vladlep commented Apr 20, 2017

Hi,

I would like my select to have dynamically 2-3 options of users and have the Nothing selected option also part of the dropdown always.
This way i can rename Nothing selected title to All users and in the dropdown you can then select one user or the All users options.

Now if i select one user i can not go back to Nothing selected (all users).

I could not find in the documentation some tips for this. Is is supported and if so could someone tell me how.

Thanks,
Vlad

@lordfriend
Copy link
Owner

If you use a native select component, it won't allow you unselect in single selection mode. So is this project.
Only multiple selection mode can unselect and what you need is to make a default option to select instead of unselect option.

@vladlep
Copy link
Author

vladlep commented Apr 20, 2017

Hi,

Thanks for the very fast reply. I thought of adding an extra option in the select like this:

     users.unshift({
          name: gettext('All users'),
          id: ""
     })

This would be just great since when I select All users the id is an empty string, which would then work just great with the API and filtering. The problem is that if I make the id an empty string the selector is initialized to Nothing selected instead of All users And when i switch back to All users it shows nothing selected.
It would work if instead of id = "" i would set id = -1 but then i would have to pre-process the data before sending to the server, which is not ideal since I wanted to make generic directive that i can re-use in slightly different ways.

@fifonik
Copy link

fifonik commented May 22, 2018

True, however when using angular's select directive it is possible to specify Select... the could be used as 'undefined'.
With this directive it is not possible so I believe it is a good idea to have alternative in-built solution.

I've implemented it in a way it is used in ui-select directive: allow-clear="true":
#186

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants