Hide tab
Support › MB Show Hide › Hide tabResolved
- This topic has 4 replies, 2 voices, and was last updated 6 years, 10 months ago by
Jason Kinney.
-
AuthorPosts
-
June 19, 2018 at 4:35 PM #10252
Jason Kinney
ParticipantIs 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.
June 20, 2018 at 8:49 PM #10276Anh Tran
KeymasterHi 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.
June 20, 2018 at 11:52 PM #10283Jason Kinney
ParticipantThe 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?
June 21, 2018 at 2:21 PM #10289Anh Tran
KeymasterI got it. I thought the tabs in the MB 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.
June 21, 2018 at 9:55 PM #10292Jason Kinney
ParticipantI 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.
-
AuthorPosts
- You must be logged in to reply to this topic.