You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Magento后台customer_address_form模态框switcherConfig二次打开失效问题

Magento后台客户地址表单switcherConfig关闭模态框后失效问题

我在Magento后台客户编辑页面的customer_address_form编辑表单中添加了自定义字段及switcherConfig,用于按条件显示/隐藏字段。页面首次加载时功能正常,但关闭模态框后立即重新打开,switcherConfig便不再生效。

我已在Magento官方GitHub提交Issue,并且制作了测试模块可在纯净环境复现该问题,Magento 2.4.4和2.4.6版本均存在此现象,测试模块代码如下:

app/code/Xtreme/TestSwitcherConfig/registration.php

<?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="http://www.w3.org/2001/XMLSchema-instance" 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="http://www.w3.org/2001/XMLSchema-instance"
      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>

请问是否有其他人遇到过该异常现象?

内容的提问来源于stack exchange,提问作者Michael Mussulis

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 23:14:54