Magento – Magento 2: How to hidden tab fieldset in form ui component
formsmagento2tabsuicomponent
Related Solutions
For that you can use field dependencies
feature of Magento, like here is the example
$status = $fieldSet->addField('status', 'select', array(
'label' => Mage::helper('module')->__('Status'),
'name' => 'status',
'values' => array(
'Approved' => 'Approved',
'Denied' => 'Denied'
)
));
$denyReason = $fieldSet->addField('denial_reason', 'textarea', array(
'label' => Mage::helper('module')->__('Denial Reason'),
'name' => 'denial_reason'
));
And add your dependencies
$this->setForm($form);
$this->setChild('form_after', $this->getLayout()->createBlock('adminhtml/widget_form_element_dependence')
->addFieldMap($status->getHtmlId(), $status->getName())
->addFieldMap($denyReason->getHtmlId(), $denyReason->getName())
->addFieldDependence(
$denyReason->getName(),
$status->getName(),
'Denied'
)
);
$denyReason
field only display If status is set to Denied
. According to this you can define your field dependencies.
Unfortunately, I don't think any of the other answers will work. One (the link to a tutorial) isn't even a UI Component. It is possible to add tabs with a UI Component. My example is for Magento 2.2 +, but I suspect it will work in earlier versions if adjusted for the old UI Component syntax.
Step #1
The following are the necessary requirements for making a UI Component with tabs work (replace all references to "referral" with your UI Component name):
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<argument name="data" xsi:type="array">
<item name="label" xsi:type="string" translate="true">Referral</item>
<item name="js_config" xsi:type="array">
<item name="provider" xsi:type="string">referral_form.referral_form_data_source</item>
</item>
</argument>
<settings>
<layout>
<!-- I assume there are other options; set the layout handle accordingly -->
<navContainerName>left</navContainerName>
<type>tabs</type>
</layout>
<deps>
<dep>referral_form.referral_form_data_source</dep>
</deps>
</settings>
<dataSource name="referral_form_data_source">
<!-- ... -->
</dataSource>
<fieldset name="referral_fieldset">
<settings>
<label translate="true">General Info</label>
</settings>
<!-- Each fieldset is a new tab -->
</fieldset>
</form>
Note: most of your example UI Component code is correct, but you need to add the following to the <settings>
node:
<navContainerName>left</navContainerName>
<type>tabs</type>
Step #2
Set the layout on the page in the layout XML file: <page layout="admin-2columns-left"/>
Magento_Customer/view/base/ui_component/customer_form.xml
is a good example in the core.
Best Answer
You should be able to use the method isComponentVisible()
And in your xml you just need to include this class in the fieldset