jcchavezs / cmb2-conditionals

Plugin to relate fields in a CMB2 metabox

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Conditionally display text box based on selected taxonomy_multicheck value

opened this issue · comments

Hello, Great plugin.

Can you please help me with taxonomy_multicheck. I'm trying to conditionally display a text box if a particular taxonomy is selected, but don't seem to be able to work out how to do it.

Many thanks

Can you send me your config file so I can test it?

Hello,

I want to be able to show the text area below when a specific taxonomy value is selected but don't know what to put in the data-conditional-value...

    $details->add_field( array(
                    'name'     => 'Edition Type',
                    'id'       => 'wiki_test_taxonomy_radio1',
                    'taxonomy' => 'product_tag', 
                    'type'     => 'taxonomy_multicheck',
                    'select_all_button' => false, 

                ));


    $details->add_field( array(
                    'name' => 'Why we chose this',
                    'id'   => $prefix . 'description',
                    'type' => 'textarea',

                    'attributes' => array(
                        'required' => true,
                        'data-conditional-id' => $prefix . 'bom',
                        'data-conditional-value' => ‘….',
                        ),
                ));

Many thanks

Hi @lw12 This should be fixed by PR #17. Would be great if you would take the time to test it. The example file in the PR contains an example of how to use this plugin with multicheck type fields.

Hi, all. I've seen a few threads about conditionals within groups, but I can't seem to get it to work. Based on reading the threads/pull requests/etc....i think it's now supported, Here's a bit of sample code that's not currently working. Basically, within a group, I want some fields to show or hide based on another field within the same group:

$metabox_content = new_cmb2_box( array(
            'id'           => $this->post_type_name . '_content',
            'title'        => __( 'Content', 'cdc' ),
            'object_types' => array( $this->post_type_name ),
            'context'      => 'normal',
            'closed'       => true,
            'priority'     => 'high',
        ) );

        $group_field_id = $metabox_content->add_field( array(
            'id'           => 'quiz_data',
            'type'         => 'group',
            'repeatable'   => true,
            'before_group' => '<p>Instructional text for the quiz items. TODO</p>',
            'options'      => array(
                'group_title'   => __( 'Question Answers {#}', 'cdc' ),
                'add_button'    => __( 'Add Another Entry', 'cdc' ),
                'remove_button' => __( 'Remove Entry', 'cdc' ),
                'sortable'      => true, // beta
            ),
        ) );

        // the field to trigger the conditional
        $metabox_content->add_group_field( $group_field_id, array(
            'name'    => __( 'Type', 'cdc' ),
            'id'      => $this->metadata_prefix . 'quiz_type',
            'type'    => 'radio_inline',
            'default' => 'question',
            'options' => array(
                'question' => __( 'Question', 'cdc' ),
                'slide'    => __( 'Slide', 'cdc' ),
            ),
        ) );

        //the field which should be shown when 'quiz_type' is 'question'
        $metabox_content->add_group_field( $group_field_id, array(
            'name'       => __( 'Question', 'cdc' ),
            'id'         => $this->metadata_prefix . 'question',
            'type'       => 'text',
            'attributes' => array(
                'data-conditional-id'    => $this->metadata_prefix . 'quiz_type',
                'data-conditional-value' => 'question',
            ),
        ) );

        //the field which should be shown when 'quiz_type' is 'slide'
        $metabox_content->add_group_field( $group_field_id, array(
            'name'       => __( 'Slide Heading', 'cdc' ),
            'id'         => 'slide_heading',
            'type'       => 'text',
            'attributes' => array(
                'data-conditional-id'    => $this->metadata_prefix . 'quiz_type',
                'data-conditional-value' => 'slide',
            ),
        ) );

There are no JS errors. All fields are showing. Changing the radio button doesn't trigger shows/hides. Any thoughts?

Were you able to get this to work @cooms13 ?