check/uncheck methods does not handle singleSelect option
See original GitHub issueLooking at the code, checkAll
and uncheckAll
methods are equivalent as clicking on the “select all” checkbox:
this.$container.off('click', '[name="btSelectAll"]')
.on('click', '[name="btSelectAll"]', function () {
var checked = $(this).prop('checked');
that[checked ? 'checkAll' : 'uncheckAll']();
that.updateSelected();
});
This is nice.
The problem is the following: there is one code for check
/ uncheck
methods and one different code for the click handler on rows checkboxes:
// check & uncheck methods
BootstrapTable.prototype.check = function (index) { this.check_(true, index); };
BootstrapTable.prototype.uncheck = function (index) { this.check_(false, index); };
BootstrapTable.prototype.check_ = function (checked, index) {
var $el = this.$selectItem.filter(sprintf('[data-index="%s"]', index)).prop('checked', checked);
this.data[index][this.header.stateField] = checked;
this.updateSelected();
this.trigger(checked ? 'check' : 'uncheck', this.data[index], $el);
};
// click handler on checkboxes
this.$selectItem = this.$body.find(sprintf('[name="%s"]', this.options.selectItemName));
this.$selectItem.off('click').on('click', function (event) {
event.stopImmediatePropagation();
var $this = $(this),
checked = $this.prop('checked'),
row = that.data[$this.data('index')];
if (that.options.maintainSelected && $(this).is(':radio')) {
$.each(that.options.data, function (i, row) {
row[that.header.stateField] = false;
});
}
row[that.header.stateField] = checked;
if (that.options.singleSelect) {
that.$selectItem.not(this).each(function () {
that.data[$(this).data('index')][that.header.stateField] = false;
});
that.$selectItem.filter(':checked').not(this).prop('checked', false);
}
that.updateSelected();
that.trigger(checked ? 'check' : 'uncheck', row, $this);
});
Looking at this, we can see that check
/ uncheck
methods doesn’t handle maintainSelected
and singleSelect
options, which can lead to have multiple rows selected even if singleSelect
is set to true true
.
Would be nice to have one single function for both (event handler and public method), what do you think ?
Issue Analytics
- State:
- Created 8 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Choosing an option to check/uncheck checkboxes not working?
Either make sure the default select selection and the default checkboxes match (as they do in your example with user1) or manually trigger ......
Read more >How do I check/uncheck a checkbox input or radio button?
You can check or uncheck a checkbox element or a radio button using the .prop() method ... How do I get the text...
Read more >How to Check and Uncheck Checkbox with JavaScript and ...
In this tutorial, you will read and learn about several JavaScript and jQuery methods for checking and unchecking a checkbox. Choose the best...
Read more ><input type="checkbox"> - HTML: HyperText Markup Language
A checkbox allows you to select single values for submission in a ... If a checkbox is unchecked when its form is submitted,...
Read more >How To Select The Check Box In Selenium With Examples
The checkbox can be turned on or off (that is checked or unchecked). A checked Checkbox is the one that is seen as...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
https://github.com/wenzhixin/bootstrap-table/commit/cedf458001c86265d5123a86e199d9257978a6c7 Thanks for @djhvscf 's PR: https://github.com/wenzhixin/bootstrap-table/pull/3685/files
Please see this fiddle https://jsfiddle.net/djhvscf/mgg544eL/9/