Commit 6eb86d07 authored by David Stutz's avatar David Stutz

Example for #163.

parent 13219440
...@@ -802,14 +802,14 @@ $("#multiselect").multiselect('dataprovider', data); ...@@ -802,14 +802,14 @@ $("#multiselect").multiselect('dataprovider', data);
case 2: case 2:
rebuildMultiselect(firstConfigurationSet); rebuildMultiselect(firstConfigurationSet);
$(this).text('Configuration Set 1'); $(this).text('Configuration Set 2');
set = 1; set = 1;
break; break;
case 1: case 1:
default: default:
rebuildMultiselect(secondConfigurationSet); rebuildMultiselect(secondConfigurationSet);
$(this).text('Configuration Set 2'); $(this).text('Configuration Set 1');
set = 2; set = 2;
break; break;
...@@ -820,7 +820,7 @@ $("#multiselect").multiselect('dataprovider', data); ...@@ -820,7 +820,7 @@ $("#multiselect").multiselect('dataprovider', data);
<table class="table table-striped"> <table class="table table-striped">
<tbody> <tbody>
<tr> <tr>
<td style="width:300px"> <td style="width:350px">
<div class="btn-group"> <div class="btn-group">
<select id="example21" multiple="multiple"> <select id="example21" multiple="multiple">
<option value="cheese">Cheese</option> <option value="cheese">Cheese</option>
...@@ -922,9 +922,11 @@ $(&quot;#multiselect&quot;).multiselect('dataprovider', data); ...@@ -922,9 +922,11 @@ $(&quot;#multiselect&quot;).multiselect('dataprovider', data);
buttonText: function(options) { buttonText: function(options) {
if (options.length == 0) { if (options.length == 0) {
return 'None selected &lt;b class=&quot;caret&quot;&gt;&lt;/b&gt;'; return 'None selected &lt;b class=&quot;caret&quot;&gt;&lt;/b&gt;';
} else if (options.length &gt; 6) { }
else if (options.length &gt; 6) {
return options.length + ' selected &lt;b class=&quot;caret&quot;&gt;&lt;/b&gt;'; return options.length + ' selected &lt;b class=&quot;caret&quot;&gt;&lt;/b&gt;';
} else { }
else {
var selected = ''; var selected = '';
options.each(function() { options.each(function() {
selected += $(this).text() + ', '; selected += $(this).text() + ', ';
...@@ -935,10 +937,12 @@ $(&quot;#multiselect&quot;).multiselect('dataprovider', data); ...@@ -935,10 +937,12 @@ $(&quot;#multiselect&quot;).multiselect('dataprovider', data);
onChange: function(element, checked) { onChange: function(element, checked) {
if(checked == true) { if(checked == true) {
// action taken here if true // action taken here if true
} else if (checked == false) { }
else if (checked == false) {
if (confirm('Do you wish to deselect the element?')) { if (confirm('Do you wish to deselect the element?')) {
// action taken here // action taken here
} else { }
else {
$(&quot;#example22&quot;).multiselect('select', element.val()); $(&quot;#example22&quot;).multiselect('select', element.val());
return false; return false;
} }
...@@ -964,6 +968,39 @@ $(&quot;#multiselect&quot;).multiselect('dataprovider', data); ...@@ -964,6 +968,39 @@ $(&quot;#multiselect&quot;).multiselect('dataprovider', data);
<button id="example33-configuration-set" class="btn btn-primary">Configuration Set 2</button> <button id="example33-configuration-set" class="btn btn-primary">Configuration Set 2</button>
</div> </div>
</td> </td>
<td>
<pre class="linenums prettyprint">
&lt;script type=&quot;text/javascript&quot;&gt;
$(document).ready(function() {
var set = 1;
$('#example33').multiselect(firstConfigurationSet);
function rebuildMultiselect(options) {
$('#example33').multiselect('setOptions', options);
$('#example33').multiselect('rebuild');
}
$('#example33-configuration-set').on('click', function(event) {
switch (set) {
case 2:
rebuildMultiselect(firstConfigurationSet);
$(this).text('Configuration Set 2');
set = 1;
break;
case 1:
default:
rebuildMultiselect(secondConfigurationSet);
$(this).text('Configuration Set 1');
set = 2;
break;
}
});
});
&lt;/script&gt;
</pre>
</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
......
...@@ -367,7 +367,7 @@ ...@@ -367,7 +367,7 @@
// Add the select all option to the select. // Add the select all option to the select.
buildSelectAll: function() { buildSelectAll: function() {
var alreadyHasSelectAll = this.$select[0][0] ? this.$select[0][0].value == this.options.selectAllValue : false; var alreadyHasSelectAll = this.$select[0][0] ? this.$select[0][0].value == this.options.selectAllValue : false;
console.log(this.options);
// If options.includeSelectAllOption === true, add the include all checkbox. // If options.includeSelectAllOption === true, add the include all checkbox.
if (this.options.includeSelectAllOption && this.options.multiple && !alreadyHasSelectAll) { if (this.options.includeSelectAllOption && this.options.multiple && !alreadyHasSelectAll) {
this.$select.prepend('<option value="' + this.options.selectAllValue + '">' + this.options.selectAllText + '</option>'); this.$select.prepend('<option value="' + this.options.selectAllValue + '">' + this.options.selectAllText + '</option>');
...@@ -532,6 +532,9 @@ ...@@ -532,6 +532,9 @@
rebuild: function() { rebuild: function() {
this.$ul.html(''); this.$ul.html('');
// Remove select all option in select.
$('option[value="' + this.options.selectAllValue + '"]', this.$select).remove();
// Important to distinguish between radios and checkboxes. // Important to distinguish between radios and checkboxes.
this.options.multiple = this.$select.attr('multiple') == "multiple"; this.options.multiple = this.$select.attr('multiple') == "multiple";
......
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