Skip to content

Commit

Permalink
add hide_results_on_select option (#2687)
Browse files Browse the repository at this point in the history
hide_results_on_select will default to true, to keep it backwards
compatible.

fixes #1546
  • Loading branch information
koenpunt committed Sep 14, 2016
1 parent ec12b87 commit 81c1725
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion coffee/chosen.jquery.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ class Chosen extends AbstractChosen
else
this.single_set_selected_text(this.choice_label(item))

this.results_hide() unless (evt.metaKey or evt.ctrlKey) and @is_multiple
this.results_hide() unless @is_multiple && (!@hide_results_on_select || (evt.metaKey or evt.ctrlKey))
this.show_search_field_default()

@form_field_jq.trigger "change", {'selected': @form_field.options[item.options_index].value} if @is_multiple || @form_field.selectedIndex != @current_selectedIndex
Expand Down
2 changes: 1 addition & 1 deletion coffee/chosen.proto.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ class @Chosen extends AbstractChosen
else
this.single_set_selected_text(this.choice_label(item))

this.results_hide() unless (evt.metaKey or evt.ctrlKey) and @is_multiple
this.results_hide() unless @is_multiple && (!@hide_results_on_select || (evt.metaKey or evt.ctrlKey))
this.show_search_field_default()

@form_field.simulate("change") if typeof Event.simulate is 'function' && (@is_multiple || @form_field.selectedIndex != @current_selectedIndex)
Expand Down
1 change: 1 addition & 0 deletions coffee/lib/abstract-chosen.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class AbstractChosen
@include_group_label_in_selected = @options.include_group_label_in_selected || false
@max_shown_results = @options.max_shown_results || Number.POSITIVE_INFINITY
@case_sensitive_search = @options.case_sensitive_search || false
@hide_results_on_select = if @options.hide_results_on_select? then @options.hide_results_on_select else true

set_default_text: ->
if @form_field.getAttribute("data-placeholder")
Expand Down
7 changes: 7 additions & 0 deletions public/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ <h3>Example:</h3>
<p>By default Chosen's search is case-insensitive. Setting this option to <code class="language-javascript">true</code> makes the search case-sensitive.</p>
</td>
</tr>
<tr>
<td>hide_results_on_select</td>
<td>true</td>
<td>
<p>By default Chosen's results are hidden after a option is selected. Setting this option to <code class="language-javascript">false</code> will keep the results open after selection. This only applies to multiple selects.</p>
</td>
</tr>
</table>

<h2><a name="attributes" class="anchor" href="#attributes">Attributes</a></h2>
Expand Down

0 comments on commit 81c1725

Please # to comment.