Support Forum
Support › Meta Box Show Hide (Javascript) › Hide tabResolved
Is it possible with any extension to hide a tab based on a field selection? If not this option is greatly needed.
For example, in tab 1 I have an Enable/Disable option. When disabled is chosen I hide all the fields on tab one, but the meta boxes/fields in the other tabs (2, 3, 4, etc.) are no longer needed when disabled it selected.
I can hide all the meta boxes in the other tabs ( 2, 3, 4, etc.), but the tab still shows and a tab with no content is not a ideal.
Hi Alex,
The Show Hide extension works for meta boxes only. To hide tabs, please use the Conditional Logic extension. Here is the tutorial on doing that.
The tabs are part of a settings page, i.e, $settings_pages[]; however, there are not css selectors to target a specific tab.
<h2 class="nav-tab-wrapper">
<a href="#tab-general">General Settings</a>
<a href="#tab-static_images">Static Ad Images</a>
</h2>
Assuming I have a css selector I can target, to hide a settings tab with the css selector .nav-tab-status and the meta field ID that controls the tab is "status" and the select option is "off" this would remove the tab:
add_filter( 'rwmb_outside_conditions', function( $conditions ) {
$conditions['.nat-tab-status'] = array(
'hidden' => array( 'status', '=', 'off' ),
);
return $conditions;
} );
FYI, Although this would not help, I added 'class' -> '.xxx' under the $settings_pages[] array and the class is not added. Does class only work on met box fields?
Also how do you wrap code in this form?
I got it. I thought the tabs in the Meta Box Tabs extension.
Anyway, have you tried using this selector a[href*="tab-general"]
?
Regarding the CSS class for settings pages, yes, it's only available for fields.
I am using the tabs extension. That is how the extension is outputting the markup.
https://www.screencast.com/t/4SlfgLGdb9l.
I have other tabs in other setting pages that are titled Static Images and the filter runs on all meta boxes so the filter would need to be able to target specific settings pages or I need unique css ID's and/or the ability to add a class to a settings page.
Otherwise, it seems that any tab that has the title Static Images will get unwillingly targeted.
I added a prefix to the tabs array key under $settings_pages[] and this works, but targeting a href in css seems hacky. A custom class wrapper would seems more appropriate and/or a filter that can target a settings page and not run on all pages.