jcchavezs / cmb2-conditionals

Plugin to relate fields in a CMB2 metabox
GNU General Public License v2.0
85 stars 61 forks source link

Multiple attributes doesn't take first data-conditional-value into account #35

Open Jnspg opened 7 years ago

Jnspg commented 7 years ago

Hello,

First of all, thank you very much for all the work you've put into this plugin, and for the help you might be able to provide.

I've created 2 radio fields and I would like a field appear according to the combo of options.

$cmb->add_field( array(
    'name' => __( 'Format', 'cw' ),
    'id' => $prefix . 'format-radio',
    'type' => 'radio_inline',
    'options' => array(
        'file' => __( 'upload file', 'cw' ),
        'link' => __( 'insert a link', 'cw' ),
    ),
) );
$cmb->add_field( array(
    'name' => __( 'Type', 'cw' ),
    'id' => $prefix . 'type-radio',
    'type' => 'taxonomy_radio_inline',
    'taxonomy' => 'news_type',
'show_option_none' => false,
) );
$cmb->add_field( array(
    'name' => __( 'Video file', 'cw' ),
    'id' => $prefix . 'video_file',
    'type' => 'file',
'attributes' => array(
     'data-conditional-id' => $prefix . 'format-radio',
     'data-conditional-value' => 'file',
),
'attributes' => array(
     'data-conditional-id' => $prefix . 'type-radio',
     'data-conditional-value' => 'video',
),
) );
$cmb->add_field( array(
    'name' => __( 'Video link', 'cw' ),
    'id' => $prefix . 'video_link',
    'type' => 'text_url',
'attributes' => array(
     'data-conditional-id' => $prefix . 'format-radio',
     'data-conditional-value' => 'link',
),
'attributes' => array(
     'data-conditional-id' => $prefix . 'type-radio',
     'data-conditional-value' => 'video',
),
) );

But only the data-conditional-value ('video') of the second attributes is taken into account, the first one ('link' or 'file') is not. As a result, the two field appears if 'video' is checked, it doesn't matter which option is checked in the first radio. I would like the file type field to appear if both options 'file' & 'video' are checked, and the url type field to appear if both options 'link' & 'video' are checked.

Could you help me?

fakeartist commented 7 years ago

Same here. Would be great if we could add an AND or OR combination of attributes.