Skip to content

Commit b6a69f4

Browse files
committed
Add an option to configure the select_all_options text
I've also included a change to the help docs to make select_all_options easier to test
1 parent f301b10 commit b6a69f4

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed

coffee/chosen.jquery.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ class Chosen extends AbstractChosen
249249

250250
select_all_setup: ->
251251
@select_all_link = $("<a />", { class: "chzn-select-all" })
252-
.html("Select all options")
252+
.html(@select_all_results)
253253
.click((evt) => this.select_all_options(evt))
254254
@dropdown.append(@select_all_link)
255255

coffee/chosen.proto.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ class @Chosen extends AbstractChosen
243243
@results_showing = false
244244

245245
select_all_setup: ->
246-
@dropdown.insert(@select_all_temp.evaluate({ "copy": "Select all options" }))
246+
@dropdown.insert(@select_all_temp.evaluate({ "copy": @select_all_results }))
247247
@select_all_link = @dropdown.down(".chzn-select-all")
248248
@select_all_link.observe("click", (evt) => this.select_all_options(evt))
249249

coffee/lib/abstract-chosen.coffee

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class AbstractChosen
4646
@default_text = @options.placeholder_text_single || @options.placeholder_text || AbstractChosen.default_single_text
4747

4848
@results_none_found = @form_field.getAttribute("data-no_results_text") || @options.no_results_text || AbstractChosen.default_no_result_text
49+
@select_all_results = @form_field.getAttribute("data-select_all_results_text") || @options.select_all_results_text || AbstractChosen.default_select_all_results_text
4950

5051
mouse_enter: -> @mouse_on_container = true
5152
mouse_leave: -> @mouse_on_container = false
@@ -244,3 +245,4 @@ class AbstractChosen
244245
@default_multiple_text: "Select Some Options"
245246
@default_single_text: "Select an Option"
246247
@default_no_result_text: "No results match"
248+
@default_select_all_results_text: "Select all options"

public/index.html

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,6 +1270,41 @@ <h2><a name="no-results-text-support" class="anchor" href="#no-results-text-supp
12701270
</div>
12711271
</div>
12721272

1273+
<h2><a name="select-all-results-text-support" class="anchor" href="#select-all-results-text-support">Select all Results Support</a></h2>
1274+
<div class="side-by-side clearfix">
1275+
<p>Adding an option to select all results is as simple as passing an option, the text can also be customised:</p>
1276+
<pre><code class="language-javascript"> $(".chzn-select").chosen({enable_select_all: true, select_all_results_text: "Select all results!"}); </code></pre>
1277+
<p></p>
1278+
<div>
1279+
<em>Multiple Select</em>
1280+
<select style="width:350px;" multiple class="chzn-select-all-results" tabindex="12">
1281+
<option value=""></option>
1282+
<option>American Black Bear</option>
1283+
<option>Asiatic Black Bear</option>
1284+
<option>Brown Bear</option>
1285+
<option>Giant Panda</option>
1286+
<option>Sloth Bear</option>
1287+
<option>Sun Bear</option>
1288+
<option>Polar Bear</option>
1289+
<option>Spectacled Bear</option>
1290+
</select>
1291+
</div>
1292+
<div>
1293+
<em>Multiple Select Custom Message</em>
1294+
<select style="width:350px;" multiple class="chzn-select-all-results-custom" tabindex="13">
1295+
<option value=""></option>
1296+
<option>American Black Bear</option>
1297+
<option>Asiatic Black Bear</option>
1298+
<option>Brown Bear</option>
1299+
<option>Giant Panda</option>
1300+
<option>Sloth Bear</option>
1301+
<option>Sun Bear</option>
1302+
<option>Polar Bear</option>
1303+
<option>Spectacled Bear</option>
1304+
</select>
1305+
</div>
1306+
</div>
1307+
12731308
<h2><a name="limit-selected-options-in-multiselect" class="anchor" href="#limit-selected-options-in-multiselect">Limit Selected Options in Multiselect</a></h2>
12741309
<div class="side-by-side clearfix">
12751310
<p>You can easily limit how many options the user can select:</p>
@@ -1462,6 +1497,8 @@ <h2><a name="credits" class="anchor" href="#credits">Credits</a></h2>
14621497
'.chzn-select-deselect' : {allow_single_deselect:true},
14631498
'.chzn-select-no-single' : {disable_search_threshold:10},
14641499
'.chzn-select-no-results': {no_results_text:'Oops, nothing found!'},
1500+
'.chzn-select-all-results': {enable_select_all:true},
1501+
'.chzn-select-all-results-custom': {enable_select_all:true, select_all_results_text: "Select all results!"},
14651502
'.chzn-select-width' : {width:"95%"}
14661503
}
14671504
for (var selector in config) {

0 commit comments

Comments
 (0)