-
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
trigger "chosen:no_result" event #1712
Conversation
this should also be implemented in the Prototype version. and the Chosen instance should be available in the event to be consistent with other events triggered by the plugin |
I agree with the others. This event is necessary since we will need to provide other options in case there are no results |
I've sent another patch, see #1717. |
Hi @lightxu, Can you please do both in the one commit here? On this same branch from your repo ( Thanks for your patch! I'm going to close #1717 for you in favor of keeping this one. |
@lightxu Ah, I also just saw that this is multiple commits. You can instead just make the commit normally and then squash all three down into just the one logical commit. Instructions here. |
Hi @tjschuck, |
Thanks, @lightxu! I mostly just triage the issues and pull requests here, so you'll have to wait for one of the @harvesthq/chosen-developers to actually review the code and merge it. Hopefully they'll sweep through soon and give you any feedback if necessary. |
Thanks @lightxu I have one nitpick and then I think this is good to go. The method that calls this is
We should also update the documentation to include this new event. |
@@ -406,6 +406,7 @@ class Chosen extends AbstractChosen | |||
no_results_html.find("span").first().html(terms) | |||
|
|||
@search_results.append no_results_html | |||
@form_field_jq.trigger("chosen:no_result") |
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.
Probably should add {chosen: this}
as second argument like all other triggers.
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.
As @stof mentioned before:
and the Chosen instance should be available in the event to be consistent with other events triggered by the plugin
Yes! And what @koenpunt said about providing a reference to Chosen. |
I've modified the code according to your comments. Although I'm not very clear about the chosen object. Since at first time, I modified in this way, but some error popup, which makes me think it is a bug. I tested the jquery version and it works, I didn't test prototype version. Thank you all for guiding me through this. |
@@ -400,6 +400,7 @@ class @Chosen extends AbstractChosen | |||
|
|||
no_results: (terms) -> | |||
@search_results.insert @no_results_temp.evaluate( terms: terms ) | |||
@form_field.fire("chosen:no_result", {chosen: this}) |
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.
no_results
here as well (instead of no_result
).
Empty search triggers "chosen:no_results" event
Thanks so much, @lightxu |
Trigger "chosen:no_result" event if function no_results is called.
A feature required by me. XD