最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

magento2 - switcherConfig stops working in customer_address_form modal - Stack Overflow

programmeradmin2浏览0评论

I modified the customer address edit form in the Magento admin customer edit page, by adding some custom fields, and a switcherConfig to show hide fields conditionally. On page load it works fine. But if you close the modal and reopen it immediately, the switcherConfig no longer works.

There's a video recording show the problem in action here:

I have reported to Magento .

Has anyone else come across this odd behavior?

I created a small test module to reproduce on a vanialla installation. It's happening both on Magento 2.4.4 and 2.4.6.

Below is the test module's code.

app/code/Xtreme/TestSwitcherConfig/etc/module.xml

<?php

\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Xtreme_TestSwitcherConfig',
    __DIR__
);

app/code/Xtreme/TestSwitcherConfig/etc/module.xml

<?xml version="1.0"?>
<config xmlns:xsi="; xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Xtreme_TestSwitcherConfig" setup_version="1.0.0">
    </module>
</config>

app/code/Xtreme/TestSwitcherConfig/view/adminhtml/ui_component/customer_address_form.xml

<?xml version="1.0"?>
<form xmlns:xsi=";
      xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/ui_component.xsd">
    <fieldset name="general">

        <field name="field1" formElement="checkbox">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="sortOrder" xsi:type="number">0</item>
                    <item name="label" xsi:type="string" translate="true">FIELD1</item>
                </item>
            </argument>
            <settings>
                <switcherConfig>
                    <rules>
                        <rule name="0">
                            <value>0</value>
                            <actions>
                                <action name="0">
                                    <target>customer_address_form.customer_address_form.general.field2</target>
                                    <callback>hide</callback>
                                </action>
                                <action name="1">
                                    <target>customer_address_form.customer_address_form.general.field3</target>
                                    <callback>hide</callback>
                                </action>
                            </actions>
                        </rule>
                        <rule name="1">
                            <value>1</value>
                            <actions>
                                <action name="0">
                                    <target>customer_address_form.customer_address_form.general.field2</target>
                                    <callback>show</callback>
                                </action>
                                <action name="1">
                                    <target>customer_address_form.customer_address_form.general.field3</target>
                                    <callback>hide</callback>
                                </action>
                            </actions>
                        </rule>
                    </rules>
                    <enabled>true</enabled>
                </switcherConfig>
                <validation>
                    <rule name="required-entry" xsi:type="boolean">true</rule>
                </validation>
                <dataType>number</dataType>
                <visible>true</visible>
                <dataScope>field1</dataScope>
            </settings>
            <formElements>
                <checkbox>
                    <settings>
                        <valueMap>
                            <map name="false" xsi:type="number">0</map>
                            <map name="true" xsi:type="number">1</map>
                        </valueMap>
                        <prefer>toggle</prefer>
                    </settings>
                </checkbox>
                <prefer>toggle</prefer>
            </formElements>
        </field>

        <field name="field2" formElement="input">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="sortOrder" xsi:type="number">1</item>
                    <item name="visible" xsi:type="boolean">false</item>
                    <item name="dataType" xsi:type="string">text</item>
                    <item name="formElement" xsi:type="string">input</item>
                    <item name="source" xsi:type="string">customer_address</item>
                    <item name="label" xsi:type="string" translate="true">FIELD2</item>
                    <item name="dataScope" xsi:type="string">field2</item>
                    <item name="validation" xsi:type="array">
                        <item name="required-entry" xsi:type="boolean">true</item>
                    </item>
                </item>
            </argument>
        </field>
        <field name="field3">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="sortOrder" xsi:type="number">2</item>
                    <item name="formElement" xsi:type="string">input</item>
                    <item name="label" xsi:type="string" translate="true">FIELD3</item>
                    <item name="visible" xsi:type="boolean">false</item>
                    <item name="dataType" xsi:type="string">text</item>
                    <item name="source" xsi:type="string">customer_address</item>
                    <item name="dataScope" xsi:type="string">field3</item>
                    <item name="validation" xsi:type="array">
                        <item name="required-entry" xsi:type="boolean">true</item>
                    </item>
                </item>
            </argument>
        </field>

    </fieldset>
</form>
发布评论

评论列表(0)

  1. 暂无评论