Commit 727b1543 authored by David Stutz's avatar David Stutz

Updated buttonText option.

The buttonText function will get the select as second parameter.
parent 28a9c6db
......@@ -156,11 +156,11 @@ If the width is defined using CSS the option should be set to false.
**buttonText**
Defining the text of the button. Must be a function returning a string. All currently selected options are passed as parameter.
Defining the text of the button. Must be a function returning a string. All currently selected options and the select are passed as parameter.
$(document).ready(function() {
$('.multiselect').multiselect({
buttonText: function(options) {
buttonText: function(options, select) {
if (options.length == 0) {
return 'None selected <b class="caret"></b>';
}
......
......@@ -565,13 +565,13 @@
<tbody>
<tr>
<td><code>buttonText</code></td>
<td>A function returning the string displayed if options are selected. All currently selected options are passed as argument. In addition HTML can be added to the button, for example the caret icon seen in the examples.</td>
<td>A function returning the string displayed if options are selected. All currently selected options and the select are passed as argument. In addition HTML can be added to the button, for example the caret icon seen in the examples.</td>
<td>
<pre class="prettyprint linenums">
&lt;script type=&quot;text/javascript&quot;&gt;
$(document).ready(function() {
$(&#39;.multiselect&#39;).multiselect({
buttonText: function(options) {
buttonText: function(options, select) {
if (options.length == 0) {
return &apos;None selected &lt;b class="caret"&gt;&lt;/b&gt;&apos;;
}
......
......@@ -60,7 +60,7 @@
}
this.$container = $(this.options.buttonContainer)
.append('<button type="button" class="multiselect dropdown-toggle ' + this.options.buttonClass + '" data-toggle="dropdown">' + this.options.buttonText($('option:selected', select)) + '</button>')
.append('<button type="button" class="multiselect dropdown-toggle ' + this.options.buttonClass + '" data-toggle="dropdown">' + this.options.buttonText($('option:selected', select), this.$select) + '</button>')
.append('<ul class="dropdown-menu"></ul>');
if (this.options.buttonWidth) {
......@@ -91,7 +91,7 @@
// Default text function will either print 'None selected' in case no option is selected,
// or a list of the selected options up to a length of 3 selected options.
// If more than 3 options are selected, the number of selected options is printed.
buttonText: function(options) {
buttonText: function(options, select) {
if (options.length == 0) {
return 'None selected <b class="caret"></b>';
}
......@@ -186,7 +186,7 @@
}
var options = $('option:selected', this.$select);
$('button', this.$container).html(this.options.buttonText(options));
$('button', this.$container).html(this.options.buttonText(options, this.$select));
this.options.onChange(option, checked);
}, this));
......@@ -215,7 +215,7 @@
}
}, this));
$('button', this.$container).html(this.options.buttonText($('option:selected', this.$select)));
$('button', this.$container).html(this.options.buttonText($('option:selected', this.$select), this.$select));
},
// Select an option by its value.
......@@ -230,7 +230,7 @@
option.prop('selected', 'selected');
var options = $('option:selected', this.$select);
$('button', this.$container).html(this.options.buttonText(options));
$('button', this.$container).html(this.options.buttonText(options, this.$select));
},
// Deselect an option by its value.
......@@ -245,7 +245,7 @@
option.removeProp('selected');
var options = $('option:selected', this.$select);
$('button', this.$container).html(this.options.buttonText(options));
$('button', this.$container).html(this.options.buttonText(options, this.$select));
},
// Rebuild the whole dropdown menu.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment