From 81c17252673433eeeee18138c8ec9849dfe1a76e Mon Sep 17 00:00:00 2001 From: Koen Punt Date: Wed, 14 Sep 2016 17:37:42 +0200 Subject: [PATCH] add hide_results_on_select option (#2687) hide_results_on_select will default to true, to keep it backwards compatible. fixes #1546 --- coffee/chosen.jquery.coffee | 2 +- coffee/chosen.proto.coffee | 2 +- coffee/lib/abstract-chosen.coffee | 1 + public/options.html | 7 +++++++ 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/coffee/chosen.jquery.coffee b/coffee/chosen.jquery.coffee index fbabf9280fd..ef271c9877f 100644 --- a/coffee/chosen.jquery.coffee +++ b/coffee/chosen.jquery.coffee @@ -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 diff --git a/coffee/chosen.proto.coffee b/coffee/chosen.proto.coffee index 9e3ae0840de..8d50a7da472 100644 --- a/coffee/chosen.proto.coffee +++ b/coffee/chosen.proto.coffee @@ -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) diff --git a/coffee/lib/abstract-chosen.coffee b/coffee/lib/abstract-chosen.coffee index 92b91ba3475..ee89e60fdf4 100644 --- a/coffee/lib/abstract-chosen.coffee +++ b/coffee/lib/abstract-chosen.coffee @@ -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") diff --git a/public/options.html b/public/options.html index 8344e252df2..1e1914c7c5b 100644 --- a/public/options.html +++ b/public/options.html @@ -130,6 +130,13 @@

Example:

By default Chosen's search is case-insensitive. Setting this option to true makes the search case-sensitive.

+ + hide_results_on_select + true + +

By default Chosen's results are hidden after a option is selected. Setting this option to false will keep the results open after selection. This only applies to multiple selects.

+ +

Attributes