Commit abdd6ab2 authored by David Stutz's avatar David Stutz

Updated documentation, added refresh method.

Updated documentation concerning the new 'onchange' option and added a
refresh method.
parent 416bf64d
# Bootstrap Multiselect # Bootstrap Multiselect
Bootstrap Multiselect is a JQuery based plugin to provide an intuitive user interface for using select inputs with the multiple attribute present. Instead of a select a bootstrap button will be shown as dropdown menu containing the single options as checkboxes. Bootstrap Multiselect is a JQuery based plugin to provide an intuitive user interface for using select inputs with the multiple attribute present. Instead of a select a bootstrap button will be shown as dropdown menu containing the single options as checkboxes.
## Examples ## Examples
These examples can also be seen in action in index.html: These examples can also be seen in action in index.html:
<link rel="stylesheet" href="css/bootstrap.min.css" type="text/css"> <link rel="stylesheet" href="css/bootstrap.min.css" type="text/css">
<script type="text/javascript" src="js/jquery.min.js"></script> <script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script> <script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/bootstrap-multiselect.js"></script> <script type="text/javascript" src="js/bootstrap-multiselect.js"></script>
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function() { $(document).ready(function() {
$('#example1').multiselect(); $('#example1').multiselect();
$('#example2').multiselect(); $('#example2').multiselect();
$('#example3').multiselect({ $('#example3').multiselect({
button: 'btn btn-link' button: 'btn btn-link'
}); });
$('#example4').multiselect({ $('#example4').multiselect({
button: 'btn btn-small' button: 'btn btn-small'
}); });
$('#example5').multiselect({ $('#example5').multiselect({
button: 'btn btn-primary disabled' button: 'btn btn-primary disabled'
}); });
$('#example6').multiselect(); $('#example6').multiselect();
$('.example7').multiselect({ $('.example7').multiselect({
container: '<span class="dropdown" />', container: '<span class="dropdown" />',
}); });
}); });
</script> </script>
<p> <p>
<select id="example1"> <select id="example1">
<option value="cheese">Cheese</option> <option value="cheese">Cheese</option>
<option value="tomatoes">Tomatoes</option> <option value="tomatoes">Tomatoes</option>
<option value="mozarella">Mozzarella</option> <option value="mozarella">Mozzarella</option>
<option value="mushrooms">Mushrooms</option> <option value="mushrooms">Mushrooms</option>
<option value="pepperoni">Pepperoni</option> <option value="pepperoni">Pepperoni</option>
<option value="onions">Onions</option> <option value="onions">Onions</option>
</select> </select>
</p> </p>
<p> <p>
<select id="example2" multiple="multiple"> <select id="example2" multiple="multiple">
<option value="cheese" selected>Cheese</option> <option value="cheese" selected>Cheese</option>
<option value="tomatoes" selected>Tomatoes</option> <option value="tomatoes" selected>Tomatoes</option>
<option value="mozarella" selected>Mozzarella</option> <option value="mozarella" selected>Mozzarella</option>
<option value="mushrooms">Mushrooms</option> <option value="mushrooms">Mushrooms</option>
<option value="pepperoni">Pepperoni</option> <option value="pepperoni">Pepperoni</option>
<option value="onions">Onions</option> <option value="onions">Onions</option>
</select> </select>
</p> </p>
<p> <p>
<select id="example3" multiple="multiple"> <select id="example3" multiple="multiple">
<option value="cheese">Cheese</option> <option value="cheese">Cheese</option>
<option value="tomatoes">Tomatoes</option> <option value="tomatoes">Tomatoes</option>
<option value="mozarella">Mozzarella</option> <option value="mozarella">Mozzarella</option>
<option value="mushrooms">Mushrooms</option> <option value="mushrooms">Mushrooms</option>
<option value="pepperoni">Pepperoni</option> <option value="pepperoni">Pepperoni</option>
<option value="onions">Onions</option> <option value="onions">Onions</option>
</select> </select>
</p> </p>
<p> <p>
<select id="example4" multiple="multiple"> <select id="example4" multiple="multiple">
<option value="cheese">Cheese</option> <option value="cheese">Cheese</option>
<option value="tomatoes">Tomatoes</option> <option value="tomatoes">Tomatoes</option>
<option value="mozarella">Mozzarella</option> <option value="mozarella">Mozzarella</option>
<option value="mushrooms">Mushrooms</option> <option value="mushrooms">Mushrooms</option>
<option value="pepperoni">Pepperoni</option> <option value="pepperoni">Pepperoni</option>
<option value="onions">Onions</option> <option value="onions">Onions</option>
</select> </select>
</p> </p>
<p> <p>
<select id="example5" multiple="multiple"> <select id="example5" multiple="multiple">
<option value="cheese">Cheese</option> <option value="cheese">Cheese</option>
<option value="tomatoes">Tomatoes</option> <option value="tomatoes">Tomatoes</option>
<option value="mozarella">Mozzarella</option> <option value="mozarella">Mozzarella</option>
<option value="mushrooms">Mushrooms</option> <option value="mushrooms">Mushrooms</option>
<option value="pepperoni">Pepperoni</option> <option value="pepperoni">Pepperoni</option>
<option value="onions">Onions</option> <option value="onions">Onions</option>
</select> </select>
</p> </p>
<p> <p>
<div class="input-prepend input-append btn-toolbar"> <div class="input-prepend input-append btn-toolbar">
<span class="add-on"><b class="icon-list-alt"></b></span> <span class="add-on"><b class="icon-list-alt"></b></span>
<select id="example6" multiple="multiple"> <select id="example6" multiple="multiple">
<option value="cheese">Cheese</option> <option value="cheese">Cheese</option>
<option value="tomatoes">Tomatoes</option> <option value="tomatoes">Tomatoes</option>
<option value="mozarella">Mozzarella</option> <option value="mozarella">Mozzarella</option>
<option value="mushrooms">Mushrooms</option> <option value="mushrooms">Mushrooms</option>
<option value="pepperoni">Pepperoni</option> <option value="pepperoni">Pepperoni</option>
<option value="onions">Onions</option> <option value="onions">Onions</option>
</select> </select>
<button class="btn btn-danger">Cancel</button> <button class="btn btn-danger">Cancel</button>
<button class="btn btn-success">Save</button> <button class="btn btn-success">Save</button>
</div> </div>
</p> </p>
<p> <p>
<div class="input-prepend input-append"> <div class="input-prepend input-append">
<span class="add-on"><b class="icon-list-alt"></b></span> <span class="add-on"><b class="icon-list-alt"></b></span>
<select class="example7" multiple="multiple"> <select class="example7" multiple="multiple">
<option value="cheese">Cheese</option> <option value="cheese">Cheese</option>
<option value="tomatoes">Tomatoes</option> <option value="tomatoes">Tomatoes</option>
<option value="mozarella">Mozzarella</option> <option value="mozarella">Mozzarella</option>
<option value="mushrooms">Mushrooms</option> <option value="mushrooms">Mushrooms</option>
<option value="pepperoni">Pepperoni</option> <option value="pepperoni">Pepperoni</option>
<option value="onions">Onions</option> <option value="onions">Onions</option>
</select> </select>
<select class="example7" multiple="multiple"> <select class="example7" multiple="multiple">
<option value="small">Small</option> <option value="small">Small</option>
<option value="medium">Medium</option> <option value="medium">Medium</option>
<option value="large">Large</option> <option value="large">Large</option>
<option value="extra">Extra Large</option> <option value="extra">Extra Large</option>
</select> </select>
<button class="btn btn-primary">Save</button> <button class="btn btn-primary">Save</button>
</div> </div>
</p> </p>
## Configuration Options ## Configuration Options
**button** **button**
Define the appearance of the button using classes. See the [Bootstrap documentation](http://twitter.github.com/bootstrap/base-css.html#buttons) for more information. Define the appearance of the button using classes. See the [Bootstrap documentation](http://twitter.github.com/bootstrap/base-css.html#buttons) for more information.
$(document).ready(function() { $(document).ready(function() {
$('.multiselect').multiselect({ $('.multiselect').multiselect({
'none': 'select something...' 'none': 'select something...'
}); });
}); });
**width** **width**
The width of the dropdown button. The width of the dropdown button.
$(document).ready(function() { $(document).ready(function() {
$('.multiselect').multiselect({ $('.multiselect').multiselect({
'width': 'auto', // Default 'width': 'auto', // Default
}); });
}); });
The width can be defined using all formats accepted by CSS: The width can be defined using all formats accepted by CSS:
100px 100px
50% 50%
auto auto
**text** **text**
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 are passed as parameter.
$(document).ready(function() { $(document).ready(function() {
$('.multiselect').multiselect({ $('.multiselect').multiselect({
'text': function(options) { 'text': function(options) {
if (options.length == 0) { if (options.length == 0) {
return 'None selected'; return 'None selected';
} }
else if (options.length > 3) { else if (options.length > 3) {
return options.length + ' selected'; return options.length + ' selected';
} }
else { else {
var selected = ''; var selected = '';
options.each(function() { options.each(function() {
selected += $(this).text() + ', '; selected += $(this).text() + ', ';
}); });
return selected.substr(0, selected.length -2); return selected.substr(0, selected.length -2);
} }
}, },
}); });
}); });
**container** **container**
The used container holding both the dropdown button and the dropdown menu. The used container holding both the dropdown button and the dropdown menu.
$('.multiselect').multiselect({ $(document).ready(function() {
container: '<span class="dropdown" />', $('.multiselect').multiselect({
}); container: '<span class="dropdown" />',
});
## Methods });
**.multiselect('destroy')** **onchange**
This method will destroy - unbind - the plugin on the given element(s). Assign an event handler to the change event:
## Roadmap / Todo $(document).ready(function() {
$('.multiselect').multiselect({
* This solution for multiple selects is not usable for mobile devices (especially with touchscreen). ALternatives: Using Popovers instead of Dropdowns or checking for mobile devices and displaying normal select field (one row) for mobile devices. onchange:function(element, checked){
alert('Change event invoked!');
## License console.log(element);
}
Copyright 2012 David Stutz });
});
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
## Methods
[http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)
**.multiselect('destroy')**
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
This method will destroy - unbind - the plugin on the given element(s).
**.multiselect('refresh')**
Refresh the selected elements depending on the selected options within the select.
## Roadmap / Todo
* This solution for multiple selects is not usable for mobile devices (especially with touchscreen). ALternatives: Using Popovers instead of Dropdowns or checking for mobile devices and displaying normal select field (one row) for mobile devices.
## License
Copyright 2012 David Stutz
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
[http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<title>Bootstrap Multiselect</title> <title>Bootstrap Multiselect</title>
<meta name="robots" content="noindex, nofollow" /> <meta name="robots" content="noindex, nofollow" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta name="copyright" content="David Stutz" /> <meta name="copyright" content="David Stutz" />
<link rel="stylesheet" href="css/bootstrap.min.css" type="text/css"> <link rel="stylesheet" href="css/bootstrap.min.css" type="text/css">
<link rel="stylesheet" href="css/bootstrap-responsive.min.css" type="text/css"> <link rel="stylesheet" href="css/bootstrap-responsive.min.css" type="text/css">
<script type="text/javascript" src="js/jquery.min.js"></script> <script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script> <script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/bootstrap-multiselect.js"></script> <script type="text/javascript" src="js/bootstrap-multiselect.js"></script>
</head> </head>
<body> <body>
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function() { $(document).ready(function() {
$('#example1').multiselect({ $('#example1').multiselect();
onchange:function(el, checked){alert('change event invoked!'); console.log(el, checked)} $('#example2').multiselect();
}); $('#example3').multiselect({
$('#example2').multiselect(); button: 'btn btn-link'
$('#example3').multiselect({ });
button: 'btn btn-link' $('#example4').multiselect({
}); button: 'btn btn-small'
$('#example4').multiselect({ });
button: 'btn btn-small' $('#example5').multiselect({
}); button: 'btn btn-primary disabled'
$('#example5').multiselect({ });
button: 'btn btn-primary disabled' $('#example6').multiselect();
}); $('.example7').multiselect({
$('#example6').multiselect(); container: '<span class="dropdown" />',
$('.example7').multiselect({ });
container: '<span class="dropdown" />', $('#example9').multiselect({
}); onchange:function(element, checked){
}); alert('Change event invoked!');
</script> console.log(element);
<div class="container"> }
<div class="hero-unit"> });
<h1>Bootstrap Multiselect</h1> });
<p> </script>
Bootstrap Multiselect is a JQuery based plugin to provide an intuitive user interface for using select inputs with the multiple attribute present. Instead of a select a bootstrap button will be shown as dropdown menu containing the single options as checkboxes. <div class="container">
</p> <div class="hero-unit">
</div> <h1>Bootstrap Multiselect</h1>
<div class="page-header"> <p>
<h1>Examples</h1> Bootstrap Multiselect is a JQuery based plugin to provide an intuitive user interface for using select inputs with the multiple attribute present. Instead of a select a bootstrap button will be shown as dropdown menu containing the single options as checkboxes.
</div> </p>
<p> </div>
The best way learning from the examples is using firebug, chrome developer tools or similar tools for your browser. Examine the generated markup and used javascript code. <div class="page-header">
</p> <h1>Examples</h1>
<table class="table table-striped"> </div>
<tr> <p>
<td> The best way learning from the examples is using firebug, chrome developer tools or similar tools for your browser. Examine the generated markup and used javascript code.
<select id="example1"> </p>
<option value="cheese">Cheese</option> <table class="table table-striped">
<option value="tomatoes">Tomatoes</option> <tr>
<option value="mozarella">Mozzarella</option> <td>
<option value="mushrooms">Mushrooms</option> <select id="example1">
<option value="pepperoni">Pepperoni</option> <option value="cheese">Cheese</option>
<option value="onions">Onions</option> <option value="tomatoes">Tomatoes</option>
</select> <option value="mozarella">Mozzarella</option>
</td> <option value="mushrooms">Mushrooms</option>
<td> <option value="pepperoni">Pepperoni</option>
Normal select. The plugin will add the <code>multiple="multiple"</code> attribute automatically. The first option is selected automatically by the browser when ommitting the <code>multiple="multiple"</code> attribute. <option value="onions">Onions</option>
</td> </select>
</tr> </td>
<tr> <td>
<td> Normal select. The plugin will add the <code>multiple="multiple"</code> attribute automatically. The first option is selected automatically by the browser when ommitting the <code>multiple="multiple"</code> attribute.
<select id="example2" multiple="multiple"> </td>
<option value="cheese" selected>Cheese</option> </tr>
<option value="tomatoes" selected>Tomatoes</option> <tr>
<option value="mozarella" selected>Mozzarella</option> <td>
<option value="mushrooms">Mushrooms</option> <select id="example2" multiple="multiple">
<option value="pepperoni">Pepperoni</option> <option value="cheese" selected>Cheese</option>
<option value="onions">Onions</option> <option value="tomatoes" selected>Tomatoes</option>
</select> <option value="mozarella" selected>Mozzarella</option>
</td> <option value="mushrooms">Mushrooms</option>
<td> <option value="pepperoni">Pepperoni</option>
Select with preselected options: <code>&lt;option value=&quot;cheese&quot; selected&gt;Cheese&lt;/option&gt;</code> <option value="onions">Onions</option>
</td> </select>
</tr> </td>
<tr> <td>
<td> Select with preselected options: <code>&lt;option value=&quot;cheese&quot; selected&gt;Cheese&lt;/option&gt;</code>
<select id="example3" multiple="multiple"> </td>
<option value="cheese">Cheese</option> </tr>
<option value="tomatoes">Tomatoes</option> <tr>
<option value="mozarella">Mozzarella</option> <td>
<option value="mushrooms">Mushrooms</option> <select id="example3" multiple="multiple">
<option value="pepperoni">Pepperoni</option> <option value="cheese">Cheese</option>
<option value="onions">Onions</option> <option value="tomatoes">Tomatoes</option>
</select> <option value="mozarella">Mozzarella</option>
</td> <option value="mushrooms">Mushrooms</option>
<td> <option value="pepperoni">Pepperoni</option>
As link using <code>button: 'btn btn-link'</code>. <option value="onions">Onions</option>
</td> </select>
</tr> </td>
<tr> <td>
<td> As link using <code>button: 'btn btn-link'</code>.
<select id="example4" multiple="multiple"> </td>
<option value="cheese">Cheese</option> </tr>
<option value="tomatoes">Tomatoes</option> <tr>
<option value="mozarella">Mozzarella</option> <td>
<option value="mushrooms">Mushrooms</option> <select id="example4" multiple="multiple">
<option value="pepperoni">Pepperoni</option> <option value="cheese">Cheese</option>
<option value="onions">Onions</option> <option value="tomatoes">Tomatoes</option>
</select> <option value="mozarella">Mozzarella</option>
</td> <option value="mushrooms">Mushrooms</option>
<td> <option value="pepperoni">Pepperoni</option>
Small button using <code>button: 'btn btn-small'</code>. <option value="onions">Onions</option>
</td> </select>
</tr> </td>
<tr> <td>
<td> Small button using <code>button: 'btn btn-small'</code>.
<select id="example5" multiple="multiple"> </td>
<option value="cheese">Cheese</option> </tr>
<option value="tomatoes">Tomatoes</option> <tr>
<option value="mozarella">Mozzarella</option> <td>
<option value="mushrooms">Mushrooms</option> <select id="example5" multiple="multiple">
<option value="pepperoni">Pepperoni</option> <option value="cheese">Cheese</option>
<option value="onions">Onions</option> <option value="tomatoes">Tomatoes</option>
</select> <option value="mozarella">Mozzarella</option>
</td> <option value="mushrooms">Mushrooms</option>
<td> <option value="pepperoni">Pepperoni</option>
Disabled using <code>button: 'btn btn-primary disabled'</code>. <option value="onions">Onions</option>
</td> </select>
</tr> </td>
<tr> <td>
<td> Disabled using <code>button: 'btn btn-primary disabled'</code>.
<div class="input-prepend input-append btn-toolbar"> </td>
<span class="add-on"><b class="icon-list-alt"></b></span> </tr>
<select id="example6" multiple="multiple"> <tr>
<option value="cheese">Cheese</option> <td>
<option value="tomatoes">Tomatoes</option> <div class="input-prepend input-append btn-toolbar">
<option value="mozarella">Mozzarella</option> <span class="add-on"><b class="icon-list-alt"></b></span>
<option value="mushrooms">Mushrooms</option> <select id="example6" multiple="multiple">
<option value="pepperoni">Pepperoni</option> <option value="cheese">Cheese</option>
<option value="onions">Onions</option> <option value="tomatoes">Tomatoes</option>
</select> <option value="mozarella">Mozzarella</option>
<button class="btn btn-danger">Cancel</button> <option value="mushrooms">Mushrooms</option>
<button class="btn btn-success">Save</button> <option value="pepperoni">Pepperoni</option>
</div> <option value="onions">Onions</option>
</td> </select>
<td> <button class="btn btn-danger">Cancel</button>
Multiple select within a group with add-ons and default container for the plugin: <code>container: '&lt;div class="btn-group" /&gt;'</code>. <button class="btn btn-success">Save</button>
</td> </div>
</tr> </td>
<tr> <td>
<td> Multiple select within a group with add-ons and default container for the plugin: <code>container: '&lt;div class="btn-group" /&gt;'</code>.
<div class="input-prepend input-append"> </td>
<span class="add-on"><b class="icon-list-alt"></b></span> </tr>
<select class="example7" multiple="multiple"> <tr>
<option value="cheese">Cheese</option> <td>
<option value="tomatoes">Tomatoes</option> <div class="input-prepend input-append">
<option value="mozarella">Mozzarella</option> <span class="add-on"><b class="icon-list-alt"></b></span>
<option value="mushrooms">Mushrooms</option> <select class="example7" multiple="multiple">
<option value="pepperoni">Pepperoni</option> <option value="cheese">Cheese</option>
<option value="onions">Onions</option> <option value="tomatoes">Tomatoes</option>
</select> <option value="mozarella">Mozzarella</option>
<select class="example7" multiple="multiple"> <option value="mushrooms">Mushrooms</option>
<option value="large">Extra Cheese</option> <option value="pepperoni">Pepperoni</option>
<option value="extra">Extra Large</option> <option value="onions">Onions</option>
</select> </select>
<button class="btn btn-primary">Save</button> <select class="example7" multiple="multiple">
</div> <option value="large">Extra Cheese</option>
</td> <option value="extra">Extra Large</option>
<td> </select>
Multiple selects within a group using <code>container: '&lt;span class="dropdown" /&gt;'</code>. <button class="btn btn-primary">Save</button>
</td> </div>
</tr> </td>
</table> <td>
<div class="page-header"> Multiple selects within a group using <code>container: '&lt;span class="dropdown" /&gt;'</code>.
<h1>Methods</h1> </td>
</div> </tr>
<script type="text/javascript"> <tr>
$(document).ready(function() { <td>
$('#example8').multiselect({ <select id="example9" multiple="multiple">
container: '<span />', <option value="cheese">Cheese</option>
}); <option value="tomatoes">Tomatoes</option>
$('#example8-destroy').on('click', function() { <option value="mozarella">Mozzarella</option>
$('#example8').multiselect('destroy'); <option value="mushrooms">Mushrooms</option>
}); <option value="pepperoni">Pepperoni</option>
}); <option value="onions">Onions</option>
</script> </select>
<table class="table table-striped"> </td>
<tbody> <td>
<tr> Using the <code>onchange</code> option you can add an event handler to the change event. The event handler gets the selected option as first parameter and a variable saying whether the option is checked or not as second one.
<td><code>.multiselect('destroy')</code></td> </td>
<td> </tr>
<div class="btn-group"> </table>
<select id="example8" multiple="multiple"> <div class="page-header">
<option value="cheese">Cheese</option> <h1>Methods</h1>
<option value="tomatoes">Tomatoes</option> </div>
<option value="mozarella">Mozzarella</option> <script type="text/javascript">
<option value="mushrooms">Mushrooms</option> $(document).ready(function() {
<option value="pepperoni">Pepperoni</option> $('#example8').multiselect({
<option value="onions">Onions</option> container: '<span />',
</select> });
<button id="example8-destroy" class="btn btn-danger">Destroy/Unbind</button> $('#example8-destroy').on('click', function() {
</div> $('#example8').multiselect('destroy');
</td> });
<td> $('#example10').multiselect({
This method is used to destroy the plugin on the given element - meaning unbinding the plugin. container: '<span />',
</td> });
</tr> $('#example10-select').on('click', function() {
</tbody> $('option[value="tomatoes"]', $('#example10')).attr('selected', true);
</table> $('option[value="mushrooms"]', $('#example10')).attr('selected', true);
<div class="page-header"> $('option[value="onions"]', $('#example10')).attr('selected', true);
<h1>Code</h1> alert('Selected Tomatoes, Mushrooms and Onions.');
</div> });
<p> $('#example10-deselect').on('click', function() {
Basic markup used in the above examples: $('option', $('#example10')).each(function(element) {
</p> $(this).attr('selected', false);
<pre> })
&lt;link rel=&quot;stylesheet&quot; href=&quot;css/bootstrap.min.css&quot; type=&quot;text/css&quot;&gt; });
$('#example10-refresh').on('click', function() {
&lt;script type=&quot;text/javascript&quot; src=&quot;js/jquery.min.js&quot;&gt;&lt;/script&gt; $('#example10').multiselect('refresh');
&lt;script type=&quot;text/javascript&quot; src=&quot;js/bootstrap.min.js&quot;&gt;&lt;/script&gt; });
&lt;script type=&quot;text/javascript&quot; src=&quot;js/bootstrap-multiselect.js&quot;&gt;&lt;/script&gt; });
</script>
&lt;script type=&quot;text/javascript&quot;&gt; <table class="table table-striped">
$(document).ready(function() { <tbody>
$(&#39;.multiselect&#39;).multiselect({ <tr>
&apos;button&apos;: &apos;btn&apos;, <td><code>.multiselect('destroy')</code></td>
&apos;width&apos;: &apos;auto&apos;, <td>
&apos;text&apos;: function(options) { <div class="btn-group">
if (options.length == 0) { <select id="example8" multiple="multiple">
return &apos;None selected&apos;; <option value="cheese">Cheese</option>
} <option value="tomatoes">Tomatoes</option>
else if (options.length > 3) { <option value="mozarella">Mozzarella</option>
return options.length + &apos; selected&apos;; <option value="mushrooms">Mushrooms</option>
} <option value="pepperoni">Pepperoni</option>
else { <option value="onions">Onions</option>
var selected = &apos;&apos;; </select>
options.each(function() { <button id="example8-destroy" class="btn btn-danger">Destroy/Unbind</button>
selected += $(this).text() + &apos;, &apos;; </div>
}); </td>
return selected.substr(0, selected.length -2); <td>
} This method is used to destroy the plugin on the given element - meaning unbinding the plugin.
} </td>
}); </tr>
}); <tr>
&lt;/script&gt; <td><code>.multiselect('refresh')</code></td>
<td>
&lt;select class=&quot;multiselect&quot; multiple=&quot;multiple&quot;&gt; <div class="btn-group">
&lt;option value=&quot;cheese&quot;&gt;Cheese&lt;/option&gt; <select id="example10" multiple="multiple">
&lt;option value=&quot;tomatoes&quot;&gt;Tomatoes&lt;/option&gt; <option value="cheese">Cheese</option>
&lt;option value=&quot;mozarella&quot;&gt;Mozzarella&lt;/option&gt; <option value="tomatoes">Tomatoes</option>
&lt;option value=&quot;mushrooms&quot;&gt;Mushrooms&lt;/option&gt; <option value="mozarella">Mozzarella</option>
&lt;option value=&quot;pepperoni&quot;&gt;Pepperoni&lt;/option&gt; <option value="mushrooms">Mushrooms</option>
&lt;option value=&quot;onions&quot;&gt;Onions&lt;/option&gt; <option value="pepperoni">Pepperoni</option>
&lt;/select&gt; <option value="onions">Onions</option>
</select>
&lt;div class=&quot;input-prepend input-append&quot;&gt; <button id="example10-select" class="btn">Select some options</button>
&lt;span class=&quot;add-on&quot;&gt;&lt;b class=&quot;icon-list-alt&quot;&gt;&lt;/b&gt;&lt;/span&gt; <button id="example10-deselect" class="btn">Deselect all</button>
&lt;select class=&quot;multiselect&quot; multiple=&quot;multiple&quot;&gt; <button id="example10-refresh" class="btn btn-primary">Refresh</button>
&lt;option value=&quot;cheese&quot;&gt;Cheese&lt;/option&gt; </div>
&lt;option value=&quot;tomatoes&quot;&gt;Tomatoes&lt;/option&gt; </td>
&lt;option value=&quot;mozarella&quot;&gt;Mozzarella&lt;/option&gt; <td>
&lt;option value=&quot;mushrooms&quot;&gt;Mushrooms&lt;/option&gt; This method is used to refresh the checked checkboxes based on the currently selected options within the select. Click &apos;Select some options&apos; so select some of the options (meaning added the <code>selected</code> attribute to some of the options). Then click refresh. The plugin will update the checkboxes accordingly.
&lt;option value=&quot;pepperoni&quot;&gt;Pepperoni&lt;/option&gt; </td>
&lt;option value=&quot;onions&quot;&gt;Onions&lt;/option&gt; </tr>
&lt;/select&gt; </tbody>
&lt;button class=&quot;btn btn-danger&quot;&gt;Cancel&lt;/button&gt; </table>
&lt;button class=&quot;btn btn-success&quot;&gt;Save&lt;/button&gt; <div class="page-header">
&lt;/div&gt; <h1>Code</h1>
</pre> </div>
<div class="page-header"> <p>
<h1>Options</h1> Basic markup used in the above examples:
</div> </p>
<table class="table table-striped"> <pre>
<thead> &lt;link rel=&quot;stylesheet&quot; href=&quot;css/bootstrap.min.css&quot; type=&quot;text/css&quot;&gt;
<tr>
<th>Option</th> &lt;script type=&quot;text/javascript&quot; src=&quot;js/jquery.min.js&quot;&gt;&lt;/script&gt;
<th width="30%">Explanation</th> &lt;script type=&quot;text/javascript&quot; src=&quot;js/bootstrap.min.js&quot;&gt;&lt;/script&gt;
<th>Usage</th> &lt;script type=&quot;text/javascript&quot; src=&quot;js/bootstrap-multiselect.js&quot;&gt;&lt;/script&gt;
</tr>
</thead> &lt;script type=&quot;text/javascript&quot;&gt;
<tbody> $(document).ready(function() {
<tr> $(&#39;.multiselect&#39;).multiselect({
<td><code>text</code></td> &apos;button&apos;: &apos;btn&apos;,
<td>A function returning the string displayed if options are selected. All currently selected options are passed as argument.</td> &apos;width&apos;: &apos;auto&apos;,
<td> &apos;text&apos;: function(options) {
<pre> if (options.length == 0) {
&lt;script type=&quot;text/javascript&quot;&gt; return &apos;None selected&apos;;
$(document).ready(function() { }
$(&#39;.multiselect&#39;).multiselect({ else if (options.length > 3) {
&apos;text&apos;: function(options) { return options.length + &apos; selected&apos;;
if (options.length == 0) { }
return &apos;None selected&apos;; else {
} var selected = &apos;&apos;;
else if (options.length > 3) { options.each(function() {
return options.length + &apos; selected&apos;; selected += $(this).text() + &apos;, &apos;;
} });
else { return selected.substr(0, selected.length -2);
var selected = &apos;&apos;; }
options.each(function() { }
selected += $(this).text() + &apos;, &apos;; });
}); });
return selected.substr(0, selected.length -2); &lt;/script&gt;
}
} &lt;select class=&quot;multiselect&quot; multiple=&quot;multiple&quot;&gt;
}); &lt;option value=&quot;cheese&quot;&gt;Cheese&lt;/option&gt;
}); &lt;option value=&quot;tomatoes&quot;&gt;Tomatoes&lt;/option&gt;
&lt;/script&gt; &lt;option value=&quot;mozarella&quot;&gt;Mozzarella&lt;/option&gt;
</pre> &lt;option value=&quot;mushrooms&quot;&gt;Mushrooms&lt;/option&gt;
</td> &lt;option value=&quot;pepperoni&quot;&gt;Pepperoni&lt;/option&gt;
</tr> &lt;option value=&quot;onions&quot;&gt;Onions&lt;/option&gt;
<tr> &lt;/select&gt;
<td><code>button</code></td>
<td>The width of the dropdown button. Default: <code>btn</code>.</td> &lt;div class=&quot;input-prepend input-append&quot;&gt;
<td> &lt;span class=&quot;add-on&quot;&gt;&lt;b class=&quot;icon-list-alt&quot;&gt;&lt;/b&gt;&lt;/span&gt;
<pre> &lt;select class=&quot;multiselect&quot; multiple=&quot;multiple&quot;&gt;
&lt;script type=&quot;text/javascript&quot;&gt; &lt;option value=&quot;cheese&quot;&gt;Cheese&lt;/option&gt;
$(document).ready(function() { &lt;option value=&quot;tomatoes&quot;&gt;Tomatoes&lt;/option&gt;
$(&#39;.multiselect&#39;).multiselect({ &lt;option value=&quot;mozarella&quot;&gt;Mozzarella&lt;/option&gt;
&apos;button&apos;: &apos;btn-primary btn-large&apos;, &lt;option value=&quot;mushrooms&quot;&gt;Mushrooms&lt;/option&gt;
}); &lt;option value=&quot;pepperoni&quot;&gt;Pepperoni&lt;/option&gt;
}); &lt;option value=&quot;onions&quot;&gt;Onions&lt;/option&gt;
&lt;/script&gt; &lt;/select&gt;
</pre> &lt;button class=&quot;btn btn-danger&quot;&gt;Cancel&lt;/button&gt;
</td> &lt;button class=&quot;btn btn-success&quot;&gt;Save&lt;/button&gt;
</tr> &lt;/div&gt;
<tr> </pre>
<td><code>width</code></td> <div class="page-header">
<td> <h1>Options</h1>
The width of the dropdown button. Default: <code>auto</code>. </div>
Allowed formats: <table class="table table-striped">
<ul> <thead>
<li><code>100px</code></li> <tr>
<li><code>50%</code></li> <th>Option</th>
<li><code>auto</code></li> <th width="30%">Explanation</th>
</ul> <th>Usage</th>
</td> </tr>
<td> </thead>
<pre> <tbody>
&lt;script type=&quot;text/javascript&quot;&gt; <tr>
$(document).ready(function() { <td><code>text</code></td>
$(&#39;.multiselect&#39;).multiselect({ <td>A function returning the string displayed if options are selected. All currently selected options are passed as argument.</td>
&apos;width&apos;: &apos;300px&apos;, <td>
}); <pre>
}); &lt;script type=&quot;text/javascript&quot;&gt;
&lt;/script&gt; $(document).ready(function() {
</pre> $(&#39;.multiselect&#39;).multiselect({
</td> &apos;text&apos;: function(options) {
</tr> if (options.length == 0) {
<tr> return &apos;None selected&apos;;
<td><code>container</code></td> }
<td> else if (options.length > 3) {
The used container holding both the dropdown button and the dropdown menu. Default: <code>&lt;div class="btn-group" /&gt;</code>. return options.length + &apos; selected&apos;;
</td> }
<td> else {
<pre> var selected = &apos;&apos;;
&lt;script type=&quot;text/javascript&quot;&gt; options.each(function() {
$(document).ready(function() { selected += $(this).text() + &apos;, &apos;;
$(&#39;.multiselect&#39;).multiselect({ });
&apos;container&apos;: &apos;&lt;span class="dropdown" /&gt;&apos;, return selected.substr(0, selected.length -2);
}); }
}); }
&lt;/script&gt; });
</pre> });
</td> &lt;/script&gt;
</tr> </pre>
</tbody> </td>
</table> </tr>
<hr> <tr>
<div> <td><code>button</code></td>
&copy; 2012 <td>The width of the dropdown button. Default: <code>btn</code>.</td>
<a href="http://davidstutz.de">David Stutz</a> - <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License v2.0</a> <td>
</div> <pre>
</div> &lt;script type=&quot;text/javascript&quot;&gt;
</body> $(document).ready(function() {
$(&#39;.multiselect&#39;).multiselect({
&apos;button&apos;: &apos;btn-primary btn-large&apos;,
});
});
&lt;/script&gt;
</pre>
</td>
</tr>
<tr>
<td><code>width</code></td>
<td>
The width of the dropdown button. Default: <code>auto</code>.
Allowed formats:
<ul>
<li><code>100px</code></li>
<li><code>50%</code></li>
<li><code>auto</code></li>
</ul>
</td>
<td>
<pre>
&lt;script type=&quot;text/javascript&quot;&gt;
$(document).ready(function() {
$(&#39;.multiselect&#39;).multiselect({
&apos;width&apos;: &apos;300px&apos;,
});
});
&lt;/script&gt;
</pre>
</td>
</tr>
<tr>
<td><code>container</code></td>
<td>
The used container holding both the dropdown button and the dropdown menu. Default: <code>&lt;div class="btn-group" /&gt;</code>.
</td>
<td>
<pre>
&lt;script type=&quot;text/javascript&quot;&gt;
$(document).ready(function() {
$(&#39;.multiselect&#39;).multiselect({
&apos;container&apos;: &apos;&lt;span class="dropdown" /&gt;&apos;,
});
});
&lt;/script&gt;
</pre>
</td>
</tr>
<tr>
<td><code>onchange</code></td>
<td>
The used container holding both the dropdown button and the dropdown menu. Default: <code>&lt;div class="btn-group" /&gt;</code>.
</td>
<td>
<pre>
&lt;script type=&quot;text/javascript&quot;&gt;
$(document).ready(function() {
$(&#39;.multiselect&#39;).multiselect({
&apos;onchange&apos;: function(element, checked) {
alert(&apos;Change event invoked!&apos;);
},
});
});
&lt;/script&gt;
</pre>
</td>
</tr>
</tbody>
</table>
<hr>
<div>
&copy; 2012
<a href="http://davidstutz.de">David Stutz</a> - <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License v2.0</a>
</div>
</div>
</body>
</html> </html>
\ No newline at end of file
...@@ -117,6 +117,20 @@ ...@@ -117,6 +117,20 @@
this.select.show(); this.select.show();
}, },
// Refreshs the checked options based on the current state of the select.
refresh: function() {
$('option', this.select).each($.proxy(function(index, element) {
if ($(element).is(':selected')) {
$('ul li input[value="' + $(element).val() + '"]', this.container).attr('checked', true);
}
else {
$('ul li input[value="' + $(element).val() + '"]', this.container).attr('checked', false);
}
}, this));
$('button', this.container).html(this.options.text($('option:selected', this.select)) + ' <b class="caret"></b>');
},
// Get options by merging defaults and given options. // Get options by merging defaults and given options.
getOptions: function(options) { getOptions: function(options) {
return $.extend({}, this.defaults, options); return $.extend({}, this.defaults, 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