Custom Fields
Re-Envisioned
Support Meta Box Conditional Logic Conditional Logic with Tabs

  • Creator
    Topic
  • #3232
    nicolas
    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?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Author
    Replies
  • #3367
    Tan Nguyen
    Participant

    Dear Nicolas,

    Thanks for using Meta Box 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
    nicolas
    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 Nguyen
    Participant

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

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

Newsletter

Subscribe to our newsletter to receive news and tutorials for Meta Box and WordPress.


grid gear info copy caret-up caret-down trash