-
Notifications
You must be signed in to change notification settings - Fork 566
Closed
Description
Describe the bug
I'm trying to conditionally do things dependent on the value of other fields, and have a change event which works great. But it does not work for multicheck fields. This is because cmb.toggleCheckBoxes uses .prop to clear/set the checkboxes but this does not fire the change event, it must be triggered manually which it isn't.
Steps to reproduce (I have confirmed I can reproduce this issue on the develop branch):
- Set up a multicheckbox
- attach
changeevent listeners that do something to the checkbox input elements - use the select/deselect all toggle
- notice the event listeners did not fire
Possible Solution
Add .trigger('change'); to the end of those lines in https://github.com/CMB2/CMB2/blob/develop/js/cmb2.js#L235
// If the button has already been clicked once...
if ( $this.data( 'checked' ) ) {
// clear the checkboxes and remove the flag
$multicheck.prop( 'checked', false ).trigger('change');
$this.data( 'checked', false );
}
// Otherwise mark the checkboxes and add a flag
else {
$multicheck.prop( 'checked', true ).trigger('change');
$this.data( 'checked', true );
}or even for a 1 line change at the end:
// If the button has already been clicked once...
if ( $this.data( 'checked' ) ) {
// clear the checkboxes and remove the flag
$multicheck.prop( 'checked', false );
$this.data( 'checked', false );
}
// Otherwise mark the checkboxes and add a flag
else {
$multicheck.prop( 'checked', true );
$this.data( 'checked', true );
}
$multicheck.trigger('change');Possible Solution's Risk Level
minimal
Additional context
This is a general jQuery issue with a general workaround.
Metadata
Metadata
Assignees
Labels
No labels