Conditional Logic with Tabs

Support MB Conditional Logic Conditional Logic with Tabs

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #3232
    nicolasnicolas
    Participant

    I'm trying to use the conditional logic extension with tabs, I would assume that this is supposed to work

    
    'tabs'        => array(
              'dish' => array(
                  'label' => esc_html__( 'Item Type and Details', $plugin_name ),
                  'icon'  => 'fa fa-cutlery', // Font Awesome
              ),
              'nutrient-content'    => array(
                  'label'   => esc_html__( 'Nutrient Content', $plugin_name ),
                  'icon'    => 'dashicons-screenoptions',
                  'visible'   => array( "{$prefix}menu_item_type", '=', 'item_type_a_la_carte' ),
              ),
    ),
    

    so essentially, the tab 'nutrien-content' should be only visible if menu_item_type is item_type_a_la_carte

    but the condition is not applied. Is tabs supporting conditional logic extension?

    #3367
    Tan NguyenTan Nguyen
    Participant

    Dear Nicolas,

    Thanks for using MB Conditional Logic, short answer: It supports Tabs.

    Because Tabs isn't Meta Box's field, it's a DOM Element so you can hide it via using DOM Selector, as already mentioned in the documentation:

    https://metabox.io/docs/meta-box-conditional-logic/#section-use-conditional-logic-outside-meta-box

    In your case, you can add this code to your theme functions.php:

    
    add_filter( 'rwmb_outside_conditions', function( $conditions )
    {
        $conditions['.rwmb-tab-nutrient-content'] = [
            'visible' => ["{$prefix}menu_item_type", 'item_type_a_la_carte']
        ];
        return $conditions;
    } );
    

    Best regards

    Tan

    #3370
    nicolasnicolas
    Participant

    Thanks, it does work by using outside conditions. I thought that adding the arg visible to the tab's array would suffice to enable the condition. Maybe this could be done in a future update?

    #3373
    Tan NguyenTan Nguyen
    Participant

    Yeah, I'll add it to future update as it's nice feature. Thanks for your question 🙂

Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘Conditional Logic with Tabs’ is closed to new replies.