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

Add support for chosen:search_updated event #3082

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions coffee/chosen.jquery.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,9 @@ class Chosen extends AbstractChosen
update_results_content: (content) ->
@search_results.html content

fire_search_updated: (search_term) ->
@form_field_jq.trigger("chosen:search_updated", {chosen: this, search_term: search_term})

results_hide: ->
if @results_showing
this.result_clear_highlight()
Expand Down
3 changes: 3 additions & 0 deletions coffee/chosen.proto.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,9 @@ class @Chosen extends AbstractChosen
update_results_content: (content) ->
@search_results.update content

fire_search_updated: (search_term) ->
@form_field.fire("chosen:search_updated", {chosen: this, search_term: search_term})

results_hide: ->
if @results_showing
this.result_clear_highlight()
Expand Down
2 changes: 2 additions & 0 deletions coffee/lib/abstract-chosen.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,11 @@ class AbstractChosen

if results < 1 and query.length
this.update_results_content ""
this.fire_search_updated query
this.no_results query
else
this.update_results_content this.results_option_build()
this.fire_search_updated query
this.winnow_results_set_highlight() unless options?.skip_highlight

get_search_regex: (escaped_search_string) ->
Expand Down
5 changes: 5 additions & 0 deletions public/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,11 @@ <h3>Example:</h3>
<td>chosen:maxselected</td>
<td>Triggered if <code class="language-javascript">max_selected_options</code> is set and that total is broken.</td>
</tr>
<tr>
<td>chosen:search_updated</td>
<td>Triggered when Chosen’s search results are updated after typing search term.
The event includes a corresponding <code class="language-javascript">search_term</code> parameter.</td>
</tr>
<tr>
<td>chosen:showing_dropdown</td>
<td>Triggered when Chosen’s dropdown is opened.</td>
Expand Down
6 changes: 5 additions & 1 deletion sass/chosen.scss
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ $chosen-sprite-retina: url('[email protected]') !default;
display: block;
width: 100%;
height: 100%;
background: $chosen-sprite no-repeat 0px 2px;
background: $chosen-sprite no-repeat 0 0;
}
}
.chosen-search {
Expand Down Expand Up @@ -421,5 +421,9 @@ $chosen-sprite-retina: url('[email protected]') !default;
background-size: 52px 37px !important;
background-repeat: no-repeat !important;
}

.chosen-container-single .chosen-single div b {
background-position: 0 2px;
}
}
/* @end */