jcchavezs / cmb2-conditionals

Plugin to relate fields in a CMB2 metabox

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Does not work correctly with repeatable type fields.

ShariqKhan2012 opened this issue · comments

Nice work. Very handy addon.
However I came across a bug while doing some testing.
If I try to make a repeatable field (say X) conditional on another field (say Y), then it does not work correctly.

The code is from the example file found in the plugin directory itself.

$cmb_demo->add_group_field( $group_id, array(
        'name' => 'Checkbox in group',
        'id'   => 'checkbox',
        'type' => 'checkbox',
    ) );

    $cmb_demo->add_group_field( $group_id, array(
        'name'       => 'Dependant field',
        'id'         => 'dependant',
        'type'       => 'text_small',
        'repeatable' => 'true',
        'attributes' => array(
            'required'               => true, // Will be required only if visible.
            'data-conditional-id'    => json_encode( array( $group_id, 'checkbox' ) ),
            'data-conditional-value' => 'on',
        ),
    ) );

The visibility is toggled fine intially, but when I try to "Add row", then things start breaking.
First, the "Add row" stops adding any row. I have to toggle visibility to off and then on (by ticking the checkbox) to see the added row. Then further if I want to delete the row, I can't do it because the "Delete row" gets disabled.

Aftyer 2-3 rounds of randomly clicking on "Add row", "Delete Row" and checking the checkbos, even the toggle visibility stops working

I wouldn't call this a bug since the plugin author never states that it will work with repeatable fields, only within repeatable groups. Since many of the core field types from the core cmb2 plugin aren't available as repeatable fields, the assumption that an addon would work for repeatables is probably unfair. That being said, getting this to work for repeatable fields would be a most excellent feature upgrade.