Commit 1f6c45e0 authored by David Stutz's avatar David Stutz

#358.

parent 1d6dc331
......@@ -224,6 +224,20 @@ $(document).ready(function() {
});
$('#example48').multiselect();
$('#example51').multiselect({
disableIfEmpty: true
});
$('#example51-rebuild').on('click', function () {
$('#example51').multiselect('rebuild');
});
$('#example51-add').on('click', function () {
$('#example51').append('<option value="cheese">Cheese</option><option value="tomato">Tomato</option>');
});
$('#example51-delete').on('click', function () {
$('option[value="cheese"]', $('#example51')).remove();
$('option[value="tomato"]', $('#example51')).remove();
});
});
</script>
......@@ -242,7 +256,7 @@ $(document).ready(function() {
<option value="onions">Onions</option>
</select>
</td>
<td>
<td width="50%">
Normal select. The plugin will do single selection using radio buttons rather than multiple selection using checkboxes.
</td>
</tr>
......@@ -612,6 +626,21 @@ $(document).ready(function() {
Use the <code>checkboxName</code> to adapt the <code>name</code> attribute of the used checkboxes.
</td>
</tr>
<tr>
<td>
<div class="btn-group">
<select id="example51" multiple="multiple"></select>
<button id="example51-add" class="btn btn-default">Add options</button>
<button id="example51-delete" class="btn btn-default">Delete options</button>
<button id="example51-rebuild" class="btn btn-primary">Rebuild</button>
</div>
</td>
<td>
<p>
Automatically disable multiselect if it has no options.
</p>
</td>
</tr>
</table>
<div class="page-header">
......@@ -1082,6 +1111,23 @@ $(document).ready(function() {
dropRight: true
});
});
&lt;/script&gt;
</pre>
</td>
</tr>
<tr>
<td><code>disableEmpty</code></td>
<td>
Set to <code>true</code> to disable the select if no options are available.
</td>
<td>
<pre class="prettyprint linenums">
&lt;script type=&quot;text/javascript&quot;&gt;
$(document).ready(function() {
$(&#39;.multiselect&#39;).multiselect({
disableEmpty: true
});
});
&lt;/script&gt;
</pre>
</td>
......
......@@ -118,6 +118,10 @@
this.updateButtonText();
this.updateSelectAll();
if (this.options.disableIfEmpty) {
this.disableIfEmpty();
}
this.$select.hide().after(this.$container);
};
......@@ -242,6 +246,7 @@
nonSelectedText: 'None selected',
nSelectedText: 'selected',
numberDisplayed: 3,
disableIfEmpty: false,
templates: {
button: '<button type="button" class="multiselect dropdown-toggle" data-toggle="dropdown"></button>',
ul: '<ul class="multiselect-container dropdown-menu"></ul>',
......@@ -913,6 +918,10 @@
this.updateButtonText();
this.updateSelectAll();
if (this.options.disableIfEmpty) {
this.disableIfEmpty();
}
if (this.options.dropRight) {
this.$ul.addClass('pull-right');
}
......@@ -965,6 +974,18 @@
.addClass('disabled');
},
/**
* Disable the multiselect if there are no options in the select.
*/
disableIfEmpty: function () {
if ($('option', this.$select).length <= 0) {
this.disable();
}
else {
this.enable();
}
},
/**
* Set the options.
*
......
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