1

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.

1 Answer 1

1

The problem is in the target field.

Instead of using

<target>customer_form.customer_form.customer.brand_rep_manager</target>

Try with this code

<target>customer_form.areas.customer.customer.brand_rep_manager</target>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.