Commit 096a1d08 authored by David Stutz's avatar David Stutz

#205

parent ade4637a
...@@ -131,7 +131,7 @@ ...@@ -131,7 +131,7 @@
$('#example14').multiselect({ $('#example14').multiselect({
buttonWidth: '500px', buttonWidth: '500px',
buttonText: function(options) { buttonText: function(options) {
if (options.length == 0) { if (options.length === 0) {
return 'None selected <b class="caret"></b>'; return 'None selected <b class="caret"></b>';
} }
else { else {
...@@ -146,7 +146,7 @@ ...@@ -146,7 +146,7 @@
$('#example16').multiselect({ $('#example16').multiselect({
onChange: function(option, checked) { onChange: function(option, checked) {
if (checked == false) { if (checked === false) {
$('#example16').multiselect('select', option.val()); $('#example16').multiselect('select', option.val());
} }
} }
...@@ -1151,7 +1151,8 @@ $(&quot;#multiselect&quot;).multiselect('dataprovider', data); ...@@ -1151,7 +1151,8 @@ $(&quot;#multiselect&quot;).multiselect('dataprovider', data);
</div> </div>
<script type="text/javascript"> <script type="text/javascript">
/** /**
* Gets whether all the options are selected * Gets whether all the options are selected.
*
* @param {jQuery} $el * @param {jQuery} $el
* @returns {bool} * @returns {bool}
*/ */
...@@ -1166,7 +1167,8 @@ $(&quot;#multiselect&quot;).multiselect('dataprovider', data); ...@@ -1166,7 +1167,8 @@ $(&quot;#multiselect&quot;).multiselect('dataprovider', data);
} }
/** /**
* Selects all the options * Selects all the options.
*
* @param {jQuery} $el * @param {jQuery} $el
* @returns {undefined} * @returns {undefined}
*/ */
...@@ -1176,7 +1178,8 @@ $(&quot;#multiselect&quot;).multiselect('dataprovider', data); ...@@ -1176,7 +1178,8 @@ $(&quot;#multiselect&quot;).multiselect('dataprovider', data);
}); });
} }
/** /**
* Deselects all the options * Deselects all the options.
*
* @param {jQuery} $el * @param {jQuery} $el
* @returns {undefined} * @returns {undefined}
*/ */
...@@ -1188,7 +1191,9 @@ $(&quot;#multiselect&quot;).multiselect('dataprovider', data); ...@@ -1188,7 +1191,9 @@ $(&quot;#multiselect&quot;).multiselect('dataprovider', data);
/** /**
* Clears all the selected options * Clears all the selected options
*
* @param {jQuery} $el * @param {jQuery} $el
* @param {jQuery} $btn
* @returns {undefined} * @returns {undefined}
*/ */
function multiselect_toggle($el, $btn) { function multiselect_toggle($el, $btn) {
...@@ -1211,10 +1216,8 @@ $(&quot;#multiselect&quot;).multiselect('dataprovider', data); ...@@ -1211,10 +1216,8 @@ $(&quot;#multiselect&quot;).multiselect('dataprovider', data);
}); });
$('#example22').multiselect({ $('#example22').multiselect({
buttonClass: 'btn',
buttonWidth: 'auto',
buttonText: function(options) { buttonText: function(options) {
if (options.length == 0) { if (options.length === 0) {
return 'None selected <b class="caret"></b>'; return 'None selected <b class="caret"></b>';
} }
else if (options.length > 6) { else if (options.length > 6) {
...@@ -1230,10 +1233,10 @@ $(&quot;#multiselect&quot;).multiselect('dataprovider', data); ...@@ -1230,10 +1233,10 @@ $(&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
} }
...@@ -1329,7 +1332,7 @@ $(&quot;#multiselect&quot;).multiselect('dataprovider', data); ...@@ -1329,7 +1332,7 @@ $(&quot;#multiselect&quot;).multiselect('dataprovider', data);
var orderCount = 0; var orderCount = 0;
$('#example38').multiselect({ $('#example38').multiselect({
buttonText: function(options) { buttonText: function(options) {
if (options.length == 0) { if (options.length === 0) {
return 'None selected <b class="caret"></b>'; return 'None selected <b class="caret"></b>';
} }
else if (options.length > 3) { else if (options.length > 3) {
...@@ -1340,10 +1343,10 @@ $(&quot;#multiselect&quot;).multiselect('dataprovider', data); ...@@ -1340,10 +1343,10 @@ $(&quot;#multiselect&quot;).multiselect('dataprovider', data);
options.each(function() { options.each(function() {
selected.push([$(this).text(), $(this).data('order')]); selected.push([$(this).text(), $(this).data('order')]);
}); });
;
selected.sort(function(a, b) { selected.sort(function(a, b) {
return a[1] - b[1]; return a[1] - b[1];
}) });
var text = ''; var text = '';
for (var i = 0; i < selected.length; i++) { for (var i = 0; i < selected.length; i++) {
...@@ -1382,6 +1385,19 @@ $(&quot;#multiselect&quot;).multiselect('dataprovider', data); ...@@ -1382,6 +1385,19 @@ $(&quot;#multiselect&quot;).multiselect('dataprovider', data);
alert(text); alert(text);
}); });
$('#example40').multiselect({
onChange: function(option, checked) {
var values = [];
$('#example40 option').each(function() {
if ($(this).val() != option.val()) {
values.push($(this).val());
}
});
alert(values);
$('#example40').multiselect('deselect', values);
}
});
}); });
</script> </script>
<table class="table table-striped"> <table class="table table-striped">
...@@ -1389,7 +1405,7 @@ $(&quot;#multiselect&quot;).multiselect('dataprovider', data); ...@@ -1389,7 +1405,7 @@ $(&quot;#multiselect&quot;).multiselect('dataprovider', data);
<tr> <tr>
<td style="width:400px"> <td style="width:400px">
<p> <p>
Use "Select" and "Deselect" to select or deselectcheese and tomatoes. Use "Values" to display the currently selected elements by using <code>$('.multiselect').val()</code>. Use "Select" and "Deselect" to select or deselect cheese and tomatoes. Use "Values" to display the currently selected elements by using <code>$('.multiselect').val()</code>.
</p> </p>
<div class="btn-group"> <div class="btn-group">
<select id="example34" multiple="multiple"> <select id="example34" multiple="multiple">
...@@ -1685,7 +1701,7 @@ $(&quot;#multiselect&quot;).multiselect('dataprovider', data); ...@@ -1685,7 +1701,7 @@ $(&quot;#multiselect&quot;).multiselect('dataprovider', data);
<tr> <tr>
<td> <td>
<p> <p>
Record the order the options are selected. When selecting an item an ordering number will be incremented and saved within the option Record the order the options are selected. When selecting an item an ordering number will be incremented and saved within the option.
</p> </p>
<div class="btn-group"> <div class="btn-group">
<select id="example38" multiple="multiple"> <select id="example38" multiple="multiple">
...@@ -1760,6 +1776,41 @@ $(&quot;#multiselect&quot;).multiselect('dataprovider', data); ...@@ -1760,6 +1776,41 @@ $(&quot;#multiselect&quot;).multiselect('dataprovider', data);
alert(text); alert(text);
}); });
}); });
&lt;/script&gt;
</pre>
</td>
</tr>
<tr>
<td>
<p>
Simulate single selections using checkboxes. The behavior will be similar to a multiselect with radio buttons.
</p>
<div class="btn-group">
<select id="example40" multiple="multiple">
<option value="cheese">Cheese</option>
<option value="tomatoes">Tomatoes</option>
<option value="mozarella">Mozzarella</option>
<option value="mushrooms">Mushrooms</option>
<option value="pepperoni">Pepperoni</option>
<option value="onions">Onions</option>
</select>
</div>
</td>
<td>
<pre class="linenums prettyprint">
&lt;script type=&quot;text/javascript&quot;&gt;
$('#example40').multiselect({
onChange: function(option, checked) {
var values = [];
$('#example40 option').each(function() {
if ($(this).val() != option.val()) {
values.push($(this).val());
}
});
alert(values);
$('#example40').multiselect('deselect', values);
}
});
&lt;/script&gt; &lt;/script&gt;
</pre> </pre>
</td> </td>
...@@ -1770,7 +1821,9 @@ $(&quot;#multiselect&quot;).multiselect('dataprovider', data); ...@@ -1770,7 +1821,9 @@ $(&quot;#multiselect&quot;).multiselect('dataprovider', data);
<div class="page-header"> <div class="page-header">
<h1><a id="additional-styling"></a>Additional Styling</h1> <h1><a id="additional-styling"></a>Additional Styling</h1>
</div> </div>
<p>For additionaly styling of the multiselect button the CSS class <code>multiselect</code> can be used.</p> <p>
For additionaly styling of the multiselect button the CSS class <code>multiselect</code> can be used.
</p>
<style media="screen" type="text/css"> <style media="screen" type="text/css">
.add-styling-1 .multiselect { .add-styling-1 .multiselect {
width: 500px; width: 500px;
...@@ -1809,7 +1862,7 @@ $(&quot;#multiselect&quot;).multiselect('dataprovider', data); ...@@ -1809,7 +1862,7 @@ $(&quot;#multiselect&quot;).multiselect('dataprovider', data);
}); });
}); });
</script> </script>
<div class="add-styling"> <div>
<table class="table table-striped"> <table class="table table-striped">
<tr class="add-styling-1"> <tr class="add-styling-1">
<td> <td>
......
...@@ -599,7 +599,6 @@ ...@@ -599,7 +599,6 @@
$checkbox.prop('checked', true); $checkbox.prop('checked', true);
$option.prop('selected', true); $option.prop('selected', true);
this.options.onChange($option, true);
} }
this.updateButtonText(); this.updateButtonText();
...@@ -625,7 +624,6 @@ ...@@ -625,7 +624,6 @@
$checkbox.prop('checked', false); $checkbox.prop('checked', false);
$option.prop('selected', false); $option.prop('selected', false);
this.options.onChange($option, false);
} }
this.updateButtonText(); this.updateButtonText();
......
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