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

Changing the collection with a selected (no longer valid) modelValue results in first element selected #184

Open
hawkeye-bot opened this issue Mar 19, 2018 · 3 comments

Comments

@hawkeye-bot
Copy link

When there is a change in the available options, the onCollectionChange function is called. In this function, there is a check that verifies if the previously selected value is still available in the new collection. If the new collection does not contain the previously selected value, the first element of the new collection is selected.

This is undesired behaviour, as it presumes to know what the right value will be in this situation. I cannot imagine there is a scenario where you would want the system to select 'the first' option available if the previous selection is no longer available.

This action is performed in https://github.com/lordfriend/nya-bootstrap-select/blob/master/src/nya-bs-select.js on line 291:
if(!contains(valuesForSelect, modelValue)) { modelValue = valuesForSelect[0];

@lordfriend
Copy link
Owner

Well, This makes sense when designing this project. As a reference, I picked system native select component which will always select an option. so I make this. Maybe today there are some components that allow use deselect or select nothing as default when they are in single select mode.

@hawkeye-bot
Copy link
Author

@lordfriend thanks for the quick response. Selecting a default value makes sense from the perspective of a native select component. However, the nya-bootstrap-select provides functionality to clear the selected value (making the element empty). Give these 2 functionalities, there is an inconsistency in the whole.

I can make a pull request, but the desired behaviour would need to be clear. I can imagine that this is something that can be configured along the lines of
if(!contains(valuesForSelect, modelValue)) { if(clearOnExpiredEntry) { modelValue = undefined; } else { modelValue = valuesForSelect[0]; } }

Does that make sense?

@lordfriend
Copy link
Owner

lordfriend commented Mar 19, 2018

Hmm, This makes sense if changes can be configured. That will maintain compatibility with some old project depending on this project.

And, if possible, add a test spec for this change.

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

2 participants