Commit 19f72356 authored by David Stutz's avatar David Stutz
parents ae1cf5c3 3a0948ac
...@@ -610,6 +610,23 @@ ...@@ -610,6 +610,23 @@
buttonContainer: '<span class="dropdown" />' buttonContainer: '<span class="dropdown" />'
}); });
}); });
</script>
</pre>
</td>
</tr>
<tr>
<td><code>label</code></td>
<td>Function to write the label of the item.</td>
<td>
<pre class="prettyprint linenums">
&lt;script type=&quot;text/javascript&quot;&gt;
$(document).ready(function() {
$(&#39;.multiselect&#39;).multiselect({
label: function(element) {
return $(element).html()+&#39; (&#39;+$(element).val()+&#39;)&#39;;
}
});
});
&lt;/script&gt; &lt;/script&gt;
</pre> </pre>
</td> </td>
...@@ -648,6 +665,44 @@ ...@@ -648,6 +665,44 @@
</pre> </pre>
</td> </td>
</tr> </tr>
<tr>
<td><code>onDropdownShow</code></td>
<td>
This event handler is triggered when the dropdown are shown.
</td>
<td>
<pre class="prettyprint linenums">
&lt;script type=&quot;text/javascript&quot;&gt;
$(document).ready(function() {
$(&#39;.multiselect&#39;).multiselect({
onDropdownShow: function(event) {
alert(&apos;Show event invoked!&apos;);
}
});
});
&lt;/script&gt;
</pre>
</td>
</tr>
<tr>
<td><code>onDropdownHide</code></td>
<td>
This event handler is triggered when the dropdown are hidden.
</td>
<td>
<pre class="prettyprint linenums">
&lt;script type=&quot;text/javascript&quot;&gt;
$(document).ready(function() {
$(&#39;.multiselect&#39;).multiselect({
onDropdownHide: function(event) {
alert(&apos;Hide event invoked!&apos;);
}
});
});
&lt;/script&gt;
</pre>
</td>
</tr>
<tr> <tr>
<td><code>maxHeight</code></td> <td><code>maxHeight</code></td>
<td> <td>
......
...@@ -39,6 +39,8 @@ ...@@ -39,6 +39,8 @@
this.options.multiple = this.$select.attr('multiple') == "multiple"; this.options.multiple = this.$select.attr('multiple') == "multiple";
this.options.onChange = $.proxy(this.options.onChange, this); this.options.onChange = $.proxy(this.options.onChange, this);
this.options.onDropdownShow = $.proxy(this.options.onDropdownShow, this);
this.options.onDropdownHide = $.proxy(this.options.onDropdownHide, this);
// Build select all if enabled. // Build select all if enabled.
this.buildContainer(); this.buildContainer();
...@@ -57,14 +59,14 @@ ...@@ -57,14 +59,14 @@
// Default options. // Default options.
defaults: { defaults: {
// Default text function will either print 'None selected' in case no // 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. // option is selected, or a list of the selected options up to a length of 3 selected options by default.
// If more than 3 options are selected, the number of selected options is printed. // If more than 3 options are selected, the number of selected options is printed.
buttonText: function(options, select) { buttonText: function(options, select) {
if (options.length == 0) { if (options.length == 0) {
return this.nonSelectedText + ' <b class="caret"></b>'; return this.nonSelectedText + ' <b class="caret"></b>';
} }
else { else {
if (options.length > 3) { if (options.length > this.numberDisplayed) {
return options.length + ' ' + this.nSelectedText + ' <b class="caret"></b>'; return options.length + ' ' + this.nSelectedText + ' <b class="caret"></b>';
} }
else { else {
...@@ -91,9 +93,21 @@ ...@@ -91,9 +93,21 @@
return selected.substr(0, selected.length - 2); return selected.substr(0, selected.length - 2);
} }
}, },
// Create label
label: function( element ){
return $(element).attr('label') || $(element).html();
},
// Is triggered on change of the selected options. // Is triggered on change of the selected options.
onChange : function(option, checked) { onChange : function(option, checked) {
},
// Triggered immediately when dropdown shown
onDropdownShow: function(event) {
},
// Triggered immediately when dropdown hidden
onDropdownHide: function(event) {
}, },
buttonClass: 'btn', buttonClass: 'btn',
dropRight: false, dropRight: false,
...@@ -113,7 +127,8 @@ ...@@ -113,7 +127,8 @@
filterBehavior: 'text', filterBehavior: 'text',
preventInputChangeEvent: false, preventInputChangeEvent: false,
nonSelectedText: 'None selected', nonSelectedText: 'None selected',
nSelectedText: 'selected' nSelectedText: 'selected',
numberDisplayed: 3
}, },
// Templates. // Templates.
...@@ -129,6 +144,8 @@ ...@@ -129,6 +144,8 @@
buildContainer: function() { buildContainer: function() {
this.$container = $(this.options.buttonContainer); this.$container = $(this.options.buttonContainer);
this.$container.on('show.bs.dropdown', this.options.onDropdownShow);
this.$container.on('hide.bs.dropdown', this.options.onDropdownHide);
}, },
buildButton: function() { buildButton: function() {
...@@ -322,7 +339,7 @@ ...@@ -322,7 +339,7 @@
} }
// Support the label attribute on options. // Support the label attribute on options.
var label = $(element).attr('label') || $(element).html(); var label = this.options.label(element);
var value = $(element).val(); var value = $(element).val();
var inputType = this.options.multiple ? "checkbox" : "radio"; var inputType = this.options.multiple ? "checkbox" : "radio";
......
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