Commit 66a6963c authored by David Stutz's avatar David Stutz

Fixed #575. The select all is not triggering the onChange anymore. Only the...

Fixed #575. The select all is not triggering the onChange anymore. Only the onSelectAll is triggered.
parent ff2cf055
...@@ -509,8 +509,7 @@ ...@@ -509,8 +509,7 @@
this.deselectAll(this.options.selectAllJustVisible); this.deselectAll(this.options.selectAllJustVisible);
} }
} }
else {
if(!isSelectAllOption){
if (checked) { if (checked) {
$option.prop('selected', true); $option.prop('selected', true);
...@@ -539,6 +538,9 @@ ...@@ -539,6 +538,9 @@
// Unselect option. // Unselect option.
$option.prop('selected', false); $option.prop('selected', false);
} }
// To prevent select all from firing onChange: #575
this.options.onChange($option, checked);
} }
this.$select.change(); this.$select.change();
...@@ -546,8 +548,6 @@ ...@@ -546,8 +548,6 @@
this.updateButtonText(); this.updateButtonText();
this.updateSelectAll(); this.updateSelectAll();
this.options.onChange($option, checked);
if(this.options.preventInputChangeEvent) { if(this.options.preventInputChangeEvent) {
return false; return false;
} }
......
...@@ -198,7 +198,7 @@ ...@@ -198,7 +198,7 @@
<td><a href="#configuration-options-nonSelectedText"><code>nonSelectedText</code></a></td> <td><a href="#configuration-options-nonSelectedText"><code>nonSelectedText</code></a></td>
</tr> </tr>
<tr> <tr>
<td><a href="#configuration-options-nSelectedText"><code>buttonText</code></a></td> <td><a href="#configuration-options-nSelectedText"><code>nSelectedText</code></a></td>
<td><a href="#configuration-options-allSelectedText"><code>allSelectedText</code></a></td> <td><a href="#configuration-options-allSelectedText"><code>allSelectedText</code></a></td>
<td><a href="#configuration-options-numberDisplayed"><code>numberDisplayed</code></a></td> <td><a href="#configuration-options-numberDisplayed"><code>numberDisplayed</code></a></td>
</tr> </tr>
...@@ -1597,6 +1597,36 @@ ...@@ -1597,6 +1597,36 @@
}); });
}); });
&lt;/script&gt; &lt;/script&gt;
</pre>
</div>
<p>
Note that the <code>allSelectedText</code> is not shown if only one option is available.
</p>
<div class="example">
<script type="text/javascript">
$(document).ready(function() {
$('#example-allSelectedText-allSelectedText-single').multiselect({
includeSelectAllOption: true,
allSelectedText: 'No option left ...'
});
});
</script>
<select id="example-allSelectedText-allSelectedText-single" multiple="multiple">
<option value="1">Option 1</option>
</select>
</div>
<div class="highlight">
<pre class="prettyprint linenums">
&lt;script type=&quot;text/javascript&quot;&gt;
$(document).ready(function() {
$('#example-allSelectedText-allSelectedText-single').multiselect({
includeSelectAllOption: true,
allSelectedText: 'No option left ...'
});
});
&lt;/script&gt;
</pre> </pre>
</div> </div>
</td> </td>
......
...@@ -455,6 +455,8 @@ describe('Bootstrap Multiselect "Select All".', function() { ...@@ -455,6 +455,8 @@ describe('Bootstrap Multiselect "Select All".', function() {
var onSelectAllTriggered = false; var onSelectAllTriggered = false;
var onDeselectAllTriggered = false; var onDeselectAllTriggered = false;
var fired = 0;
beforeEach(function() { beforeEach(function() {
var $select = $('<select id="multiselect" multiple="multiple"></select>'); var $select = $('<select id="multiselect" multiple="multiple"></select>');
...@@ -473,6 +475,9 @@ describe('Bootstrap Multiselect "Select All".', function() { ...@@ -473,6 +475,9 @@ describe('Bootstrap Multiselect "Select All".', function() {
}, },
onDeselectAll: function() { onDeselectAll: function() {
onDeselectAllTriggered = true; onDeselectAllTriggered = true;
},
onChange: function(option, checked) {
fired++;
} }
}); });
}); });
...@@ -612,6 +617,13 @@ describe('Bootstrap Multiselect "Select All".', function() { ...@@ -612,6 +617,13 @@ describe('Bootstrap Multiselect "Select All".', function() {
expect(onSelectAllTriggered).toBe(true); expect(onSelectAllTriggered).toBe(true);
}); });
it('Should not trigger onChange for select all option.', function() {
fired = 0;
expect(fired).toBe(0);
$('#multiselect-container input[value="multiselect-all"]').click();
expect(fired).toBe(0);
});
afterEach(function() { afterEach(function() {
$('#multiselect').multiselect('destroy'); $('#multiselect').multiselect('destroy');
$('#multiselect').remove(); $('#multiselect').remove();
......
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