-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Add option to limit selected options in multiselect #530
Conversation
Thank you for this. I am looking for the exact same feature. I hope it will be merged soon! |
Yes, thank you - looking forward to seeing this in a build! |
Great! Hope this feature will be in main build. |
up!! |
@@ -31,6 +31,7 @@ class AbstractChosen | |||
@disable_search_threshold = @options.disable_search_threshold || 0 | |||
@search_contains = @options.search_contains || false | |||
@choices = 0 | |||
@limit_choices = @options.limit || false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think using a big number is preferable to false as a default. Ideally, we'd use the actual length of the options for the limit as a default, but I think using something like 9999 is probably safe for all practical purposes. Using a default of 999 would eliminate part of the conditional.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
putting a number as default value would require changing the way the default is applied, as using ||
would forbid forcing false
as value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using false
as a default complicates the logic when we test for it later. Using a number would allow one check: if @limit_choices >= @choices
Thanks - just a few quibbles and we can get this merged in. I think the name property should not be called I also think that an event should be triggered if the limit is hit so that a message could possibly be displayed. Maybe something like I also made a comment where the default is set. |
I'll get into it. Speaking of ambiguity |
+1 for |
Yeah, that sounds great. |
Thanks a lot, @Polycode. It's really nice to close 3 issues with one PR. I don't think this is perfect, but I think it'll help people who are careful with using it. It's pretty confusing to just have the results not show up with no explanation to the user, but the event gives a nice way to handle that situation. |
Thank you. However I disagree about confusion - it's like having |
Though maxlength on an input is developer-friendly, it's not particularly user friendly. Stopping a user's intended behavior without explaining why isn't a wonderful experience. "Not perfect" does not mean it's bad, though -- I'm happy to have this merged in. I agree that the event is probably coming too late for the user. Using Chosen's current behavior It is definitely possible to monitor the number of elements selected. $("#some_field").val().length This is a good something to build off of going forward. Thanks again @Polycode |
As addressed in issues #154 #463 #494 this adds option to limit number of selected options for multiselect.
$(select).chosen({ limit : 5 });