TransWikia.com

Problem for create dependency between Custom Fields and Customer Group Id field in customer form UI component

Magento Asked by Denis Spalenza on December 14, 2021

I created a new extension that add more fields to customer to control sales reps users. The fields and data are working as expected. But I want make the new fields be hide or disable for some customer groups.

I have two specifics customer groups for sales reps, so the new fields should be visible just for those customer which matchs in these groups inside admin customer form. So in other words, create a dependency between the new fields and the customer group select element.

<?xml version="1.0" encoding="UTF-8"?>
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
    <fieldset name="customer">
        <field name="group_id" formElement="select">
            <settings>
                <switcherConfig>
                    <rules>
                        <rule name="0">
                            <value>5</value>
                            <actions>
                                <action name="0">
                                    <target>customer_form.customer_form.customer.brand_rep_manager</target>
                                    <callback>hide</callback>
                                </action>
                                <action name="1">
                                    <target>customer_form.customer.brand_of_rep</target>
                                    <callback>hide</callback>
                                </action>
                            </actions>
                        </rule>
                        <rule name="1">
                            <value>16</value>
                            <actions>
                                <action name="0">
                                    <target>customer_form.customer_form.customer.brand_rep_manager</target>
                                    <callback>show</callback>
                                </action>
                                <action name="1">
                                    <target>customer_form.customer_form.customer.brand_of_rep</target>
                                    <callback>show</callback>
                                </action>
                            </actions>
                        </rule>
                    </rules>
                    <enabled>true</enabled>
                </switcherConfig>
            </settings>
        </field>
        <field name="brand_rep_manager" sortOrder="970" formElement="checkbox">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="default" xsi:type="number">0</item>
                </item>
            </argument>
        </field>
        <field name="brand_of_rep" sortOrder="975" formElement="select">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="default" xsi:type="string"></item>
                </item>
            </argument>
        </field>
    </fieldset>
</form>

Also I tried some variations and even added the <switcherConfig> inside the original customer_form.xml just to test it, but didn’t work too.

And I already checked some previous question here and post like this one: https://www.hungersoft.com/info/dependent-fields-ui-component-form-magento2-without-js
I didn’t see any reason for it not works as well.

One Answer

The problem is in the target field.

Instead of customer_form.customer_form.customer.brand_rep_manager

Try with customer_form.areas.customer.customer.brand_rep_manager

Answered by mariana rodriguez on December 14, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP