I am trying to add a switcherConfig
on one of my ui component field. Its a simple show/hide rule based on value of one field.
This code Works:
<?xml version="1.0" ?>
<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="js_config" xsi:type="array">
<item name="provider" xsi:type="string">my_form.data_source</item>
</item>
<item name="label" xsi:type="string" translate="true">General Information</item>
<item name="template" xsi:type="string">templates/form/collapsible</item>
</argument>
<settings>
<buttons>
<button name="back" class="Custom\Vendor\Block\Adminhtml\Vendor\Edit\BackButton"/>
<button name="delete" class="Custom\Vendor\Block\Adminhtml\Vendor\Edit\DeleteButton"/>
<button name="save" class="Custom\Vendor\Block\Adminhtml\Vendor\Edit\SaveButton"/>
<button name="save_and_continue" class="Custom\Vendor\Block\Adminhtml\Vendor\Edit\SaveAndContinueButton"/>
</buttons>
<namespace>my_form</namespace>
<dataScope>data</dataScope>
</settings>
<fieldset name="general">
<settings>
<label>General</label>
</settings>
<field name="source_field" formElement="select" sortOrder="10">
<argument name="data" xsi:type="array">
<item name="options" xsi:type="object">Custom\Vendor\Model\Source\MyOptions</item>
<item name="config" xsi:type="array">
<item name="source" xsi:type="string">source_field</item>
</item>
</argument>
<settings>
<switcherConfig>
<rules>
<rule name="0">
<value>0</value>
<actions>
<action name="0">
<target>my_form.my_form.general.target_field</target>
<callback>hide</callback>
</action>
</actions>
</rule>
<rule name="1">
<value>1</value>
<actions>
<action name="0">
<target>my_form.my_form.general.target_field</target>
<callback>show</callback>
</action>
</actions>
</rule>
</rules>
<enabled>true</enabled>
</switcherConfig>
<dataType>number</dataType>
<label translate="true">Parent Field</label>
<dataScope>parent_field</dataScope>
</settings>
</field>
<field name="target_field" formElement="input" sortOrder="30">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="source" xsi:type="string">Form</item>
</item>
</argument>
<settings>
<dataType>text</dataType>
<label translate="true">Name</label>
<dataScope>name</dataScope>
<validation>
<rule name="required-entry" xsi:type="boolean">true</rule>
<rule name="max_text_length" xsi:type="number">100</rule>
</validation>
</settings>
</field>
</fieldset>
</form>
This code does not work:
<?xml version="1.0" ?>
<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="js_config" xsi:type="array">
<item name="provider" xsi:type="string">my_form.data_source</item>
</item>
<item name="label" xsi:type="string" translate="true">General Information</item>
<!-- <item name="template" xsi:type="string">templates/form/collapsible</item> -->
</argument>
<settings>
<buttons>
<button name="back" class="Custom\Vendor\Block\Adminhtml\Vendor\Edit\BackButton"/>
<button name="delete" class="Custom\Vendor\Block\Adminhtml\Vendor\Edit\DeleteButton"/>
<button name="save" class="Custom\Vendor\Block\Adminhtml\Vendor\Edit\SaveButton"/>
<button name="save_and_continue" class="Custom\Vendor\Block\Adminhtml\Vendor\Edit\SaveAndContinueButton"/>
</buttons>
<namespace>my_form</namespace>
<dataScope>data</dataScope>
<layout>
<navContainerName>left</navContainerName>
<type>tabs</type>
</layout>
</settings>
<fieldset name="general">
<settings>
<label>General</label>
</settings>
<field name="source_field" formElement="select" sortOrder="10">
<argument name="data" xsi:type="array">
<item name="options" xsi:type="object">Custom\Vendor\Model\Source\MyOptions</item>
<item name="config" xsi:type="array">
<item name="source" xsi:type="string">source_field</item>
</item>
</argument>
<settings>
<switcherConfig>
<rules>
<rule name="0">
<value>0</value>
<actions>
<action name="0">
<target>my_form.my_form.general.target_field</target>
<callback>hide</callback>
</action>
</actions>
</rule>
<rule name="1">
<value>1</value>
<actions>
<action name="0">
<target>my_form.my_form.general.target_field</target>
<callback>show</callback>
</action>
</actions>
</rule>
</rules>
<enabled>true</enabled>
</switcherConfig>
<dataType>number</dataType>
<label translate="true">Parent Field</label>
<dataScope>parent_field</dataScope>
</settings>
</field>
<field name="target_field" formElement="input" sortOrder="30">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="source" xsi:type="string">Form</item>
</item>
</argument>
<settings>
<dataType>text</dataType>
<label translate="true">Name</label>
<dataScope>name</dataScope>
<validation>
<rule name="required-entry" xsi:type="boolean">true</rule>
<rule name="max_text_length" xsi:type="number">100</rule>
</validation>
</settings>
</field>
</fieldset>
</form>
This code works if I use collapsible layout but stops working when I change it to tabs layout. Did anyone face similar issue? Any suggestion on how to solve it?