将网格添加到Admin客户编辑表单后,验证错误


8

我已经在Magento管理员的“客户编辑”表单中成功添加了带有网格的自定义标签。该选项卡<insertListing>在其布局XML中使用标签来呈现网格,该网格应能正常工作。但是,当我尝试保存客户时,表单验证会引发错误。我已经调试这一点,似乎当validate()的方法tab_group.js试图调用该标签的validate方法,它返回undefined。我已将其与“商店信用”选项卡进行了比较,该选项卡是使用不推荐使用的Grid块创建的,对于该元素,它返回一个空数组。我的配置中缺少什么吗?

错误:

tab_group.js:68 Uncaught TypeError: Cannot read property 'valid' of undefined
    at tab_group.js:68
    at Function.findIndex (underscore.js:644)
    at Function._.find._.detect (underscore.js:206)
    at UiClass.validate (tab_group.js:67)
    at Array.some (<anonymous>)
    at UiClass.onValidate (tab_group.js:86)
    at setNested (objects.js:43)
    at Object.nested (objects.js:117)
    at UiClass.set (element.js:305)
    at updateValue (links.js:80)
(anonymous) @ tab_group.js:68
(anonymous) @ underscore.js:644
_.find._.detect @ underscore.js:206
validate @ tab_group.js:67
onValidate @ tab_group.js:86
setNested @ objects.js:43
nested @ objects.js:117
set @ element.js:305
updateValue @ links.js:80
(anonymous) @ events.js:87
trigger @ events.js:84
trigger @ events.js:162
validate @ form.js:333
save @ form.js:261
dispatch @ jquery.js:5226
elemData.handle @ jquery.js:4878

标签版式XML(view/base/ui_component/customer_form.xml):

<?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">
    <fieldset name="downloaded_blueprints" sortOrder="1000">
        <settings>
            <label translate="true">Downloaded Blueprints</label>
        </settings>
        <insertListing name="downloaded_blueprints_listing">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="source" xsi:type="string">blueprint_download</item>
                </item>
            </argument>
            <settings>
                <externalProvider>${ $.ns }.downloaded_blueprints_listing_data_source</externalProvider>
                <autoRender>true</autoRender>
                <dataScope>downloaded_blueprints_listing</dataScope>
                <ns>downloaded_blueprints_listing</ns>
                <exports>
                    <link name="customerId">${ $.externalProvider }:params.customer_id</link>
                </exports>
                <imports>
                    <link name="customerId">${ $.provider }:data.customer.entity_id</link>
                </imports>
            </settings>
        </insertListing>
    </fieldset>
</form>

请共享您的网格代码,当前共享的代码工作正常。
kunj

Answers:


8

这是错误。因此,您可以在上面添加mixin。请尝试以下方式:

VendorName / ModuleName / view / adminhtml / requirejs-config.js


var config = {
    "config": {
        'mixins': {
            'Magento_Ui/js/form/components/tab_group': {
                'VendorName_ModuleName/js/mixin/form/components/tab_group': true
            }
        }
    }
};

VendorName / ModuleName / view / adminhtml / web / js / mixin / form / components / tab_group.js


define([
    'underscore'
], function (_) {
    'use strict';

    return function (TabGroup) {
        return TabGroup.extend({
            /**
             * Delegates 'validate' method on element, then reads 'invalid' property
             * of params storage, and if defined, activates element, sets
             * 'allValid' property of instance to false and sets invalid's
             * 'focused' property to true.
             *
             * @param {Object} elem
             */
            validate: function (elem) {
                // Pass through if element is not fieldset
                if (elem.index !== 'downloaded_blueprints') {
                    return this._super();
                }

                var result = elem.delegate('validate'),
                    invalid;

                invalid = _.find(result, function (item) {
                    if (item === undefined) {
                        return 0;
                    }

                    return !item.valid;
                });

                if (invalid) {
                    elem.activate();
                    invalid.target.focused(true);
                }

                return invalid;
            }
        });
    }
});

删除pub / static / *并部署静态内容


谢谢。做了一些修改,效果很好。
约瑟夫·利迪

@JosephLeedy,您进行了哪些修改。添加此JS后,仍然出现相同的错误
Jaisa

@Jaisa如果您查看答案修订,您会看到我的更改。
约瑟夫·李迪

您好@JosephLeedy,我在企业中遇到了相同的错误,我应用了此更改,但即使删除了pub / static var生成并清除了缓存,它仍然显示相同的错误。你能帮我吗?我正在使用M2.3.1
Pribhav

很棒的工作..非常感谢。
Mohit Kumar Arora
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.