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

Changed event triggered when using data-max-options? #1291

Closed
alexcrooks opened this issue Feb 9, 2016 · 3 comments
Closed

Changed event triggered when using data-max-options? #1291

alexcrooks opened this issue Feb 9, 2016 · 3 comments

Comments

@alexcrooks
Copy link

I've been working with bootstrap-select recently, in particular with dropdown menus using the data-max-options option, and how it triggers the changed.bs.select event.

So say we have a dropdown as such, with data-max-options="2"

| 2 selected |
| Opt 1 √    |
| Opt 2 √    |
| Opt 3      |

When we select Opt 3, the dropdown changes to look like

| 2 selected |
| Opt 1 √    |
| Opt 2      |
| Opt 3 √    |

Currently one event is fired: changed.bs.select for Opt 3 added.

In my opinion, two events should be fired: changed.bs.select for Opt 2 removed, and then changed.bs.select for Opt 3 added.

I'm happy to submit a PR for this if you think it is a valid bug, just wanted to hear your thoughts before writing the code.

@caseyjhol
Copy link
Member

Hrmmm...that isn't normal functionality for that feature. If maxOptions is set to 2, and you have 2 options already selected, selecting a 3rd option should show a notification that the limit is 2, and the third option won't be selected. There is a bug there, however. Since the 3rd option is never technically selected, the changed.bs.select event shouldn't even be fired.

@alexcrooks
Copy link
Author

I'm not sure if I agree. Say I have a native dropdown as such:

<select>
  <option selected>Foo</option>
  <option>Bar</option>
  <option>Baz</option>
</select>

When I select "Bar", it becomes selected -- there aren't any implementations of <select> that show a notification, they all change the selected attribute to the newly-selected option. A native <select> is functionally equivalent to <select class="selectpicker" data-max-options="1">, so I think it makes sense that the two share the same UX.

If you're not showing a notification, though, then what is the logic for which option you unselect? Oldest-gets-dropped?

With a native dropdown, when you select an option, the previously selected option becomes unselected, but it only fires a single changed event. So maybe this whole issue is moot? My current use-case for bootstrap-select needs to know what's unselected but it's sounding like I should be keeping track of that state in my implementation instead.

@caseyjhol
Copy link
Member

If you're using maxOptions, and you've reached your limit, a notification alerts the user - otherwise it would be too confusing to change the user's selection. We could maybe show a notification prior to attempting to select the extra option, but that's a different topic.

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