• Resolved Stuart Shields

    (@sbshields9)


    Hi,

    I was wondering if you could please verify the default behavior of how multicheck boxes work.

    Do you need at-least one checkbox checked?

    So currently, I have 1 checkbox, if I check it, it saves as it should.

    However as soon as I uncheck it, on save the box remains checked.

    The database reflects no change was made (so it stores the value of the checkbox).

    This happens in both Firefox and Chrome, I’m wondering if this is the expected behavior and if so, is there a way around it?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    You should be able to deselect everything, save, and have things remaining deselected.

    I just tried with the example found at https://github.com/CMB2/CMB2/wiki/Field-Types#multicheck-and-multicheck_inline and it worked for me.

    Can you provide the CMB2 config you’re using for your example?

    Thread Starter Stuart Shields

    (@sbshields9)

    Here is how we are calling the multicheck if you need more let me know. Also this is running on an options page if that helps.

     [
    	[
    		'name'    => __( 'Active feeds', 'asd-feeds' ),
    		'desc'    => __( 'Activate / Deactivate feeds', 'asd-feeds' ),
    		'id'      => 'active_feeds',
    		'type'    => 'multicheck',
    		'options' => array_column( $this->feeds, 'title', 'id' ),
    	],
    	[
    		'name' => __( 'Debug mode', 'asd-feeds' ),
    		'desc' => __( 'Enable debug mode, ie: more verbose logging.', 'asd-feeds' ),
    		'id'   => 'debug',
    		'type' => 'checkbox',
    	],
    ];
    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Can you provide a static version of what is found in the feeds property for your usage? the part from $this->feeds

    Thread Starter Stuart Shields

    (@sbshields9)

    Do you have an email address that I can share a gist with? I’d rather not show code from a client.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    [email protected] will reach me

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    confirming i did receive the email and have the php class provided. Took a few to figure out how to get a similar setup, set up. I replaced the $this->feeds with a generic array of key/value pairs.

    Definitely able to recreate this one, and looking over the GitHub issues list, we had a similar case this past summer, that is still unresolved.

    https://github.com/CMB2/CMB2/issues/978

    Three options I can see at the moment.

    1. This is a new one that I didn’t think of when I filed the issue. Have the multi-check option be the last time in the page. It seems to clear appropriately in that situation.

    2. First from the GitHub issue above. I was able to get around it by setting a value in the 2nd one, and then unchecking the first ones, and that seemed to work. Then, on a 2nd save of the page, uncheck the second item and then all of them were empty finally. This was able to be done without the hidden field that you set.

    3. Second from the GitHub issue above. An alternate idea that may help would just be to have a “none” option that you don’t actually do anything with on the frontend or wherever you’re using these values at.

    Not sure exactly what the project specs are and how flexible you’ll be able to be here. Given the wonky nature of 2 of the ideas, I’d probably personally settle on idea 3 with the “none” option as a default.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Multicheck boxes default behavior’ is closed to new replies.