2

I have defined admin form field dependency in my uicomponent form

<field name="redirect_in">
    <argument name="data" xsi:type="array">
        <item name="options" xsi:type="object">Namespace\Modulename\Model\Config\Source\Options</item>
        <item name="config" xsi:type="array">
            <item name="dataType" xsi:type="string">int</item>
            <item name="label" xsi:type="string" translate="true">Store Info</item>
            <item name="component" xsi:type="string">Namespace_Modulename/js/form/element/options</item>
            <item name="formElement" xsi:type="string">select</item>
            <item name="source" xsi:type="string">modulename</item>
            <item name="dataScope" xsi:type="string">redirect_in</item>
            <item name="default" xsi:type="string">0</item>
            <item name="validation" xsi:type="array">
                <item name="required-entry" xsi:type="boolean">true</item>
            </item>
        </item>
    </argument>
</field>
<field name="storeviews">
    <argument name="data" xsi:type="array">
        <item name="options" xsi:type="object">Magento\Store\Ui\Component\Listing\Column\Store\Options</item>
        <item name="config" xsi:type="array">
            <item name="dataType" xsi:type="string">int</item>
            <item name="label" xsi:type="string" translate="true">Store View</item>
            <item name="formElement" xsi:type="string">select</item>
            <item name="source" xsi:type="string">modulename</item>
            <item name="dataScope" xsi:type="string">redirect_store_id</item>
            <item name="visibleValue" xsi:type="string">0</item>
            <item name="visible" xsi:type="boolean">true</item>                        
            <item name="validation" xsi:type="array">
                <item name="required-entry" xsi:type="boolean">true</item>
            </item>
        </item>
    </argument>
</field>
<field name="external_url">
    <argument name="data" xsi:type="array">
        <item name="config" xsi:type="array">
            <item name="dataType" xsi:type="string">text</item>
            <item name="label" xsi:type="string" translate="true">External Link</item>
            <item name="formElement" xsi:type="string">input</item>
            <item name="source" xsi:type="string">modulename</item>
            <item name="dataScope" xsi:type="string">redirect_external_url</item>
            <item name="visibleValue" xsi:type="string">1</item>
            <item name="visible" xsi:type="boolean">false</item>                        
            <item name="validation" xsi:type="array">
                <item name="required-entry" xsi:type="boolean">true</item>
                <item name="validate-url" xsi:type="boolean">true</item>
            </item>
        </item>
    </argument>
</field>

The dependent js to get and reterive the value

Namespace\Modulename\Model\Config\Source\Options

define([
    'underscore',
    'uiRegistry',
    'Magento_Ui/js/form/element/select',
    'Magento_Ui/js/modal/modal'
], function (_, uiRegistry, select, modal) {
    'use strict';

    return select.extend({

        initialize: function () {
            this._super();
            var storeviewField = uiRegistry.get('index = storeviews');
            var externalUrl = uiRegistry.get('index = external_url');
            if(this.value() == 1){
                externalUrl.show();
                storeviewField.hide();
            } else {
                storeviewField.show();
                externalUrl.hide();
            }

            return this;
        },

    });
});

This works great until I merge JS from magento setting.

I get the following error

storeviewField undifined

Why is it causing issue when I merge the JS Files?

| improve this question | | | | |
1

I had the same issue I moved my column above.

Try moving your storeviews column above redirect_in:

<field name="storeviews">
    <argument name="data" xsi:type="array">
        <item name="options" xsi:type="object">Magento\Store\Ui\Component\Listing\Column\Store\Options</item>
        <item name="config" xsi:type="array">
            <item name="dataType" xsi:type="string">int</item>
            <item name="label" xsi:type="string" translate="true">Store View</item>
            <item name="formElement" xsi:type="string">select</item>
            <item name="source" xsi:type="string">modulename</item>
            <item name="dataScope" xsi:type="string">redirect_store_id</item>
            <item name="visibleValue" xsi:type="string">0</item>
            <item name="visible" xsi:type="boolean">true</item>
            <item name="validation" xsi:type="array">
                <item name="required-entry" xsi:type="boolean">true</item>
            </item>
        </item>
    </argument>
</field>
<field name="external_url">
    <argument name="data" xsi:type="array">
        <item name="config" xsi:type="array">
            <item name="dataType" xsi:type="string">text</item>
            <item name="label" xsi:type="string" translate="true">External Link</item>
            <item name="formElement" xsi:type="string">input</item>
            <item name="source" xsi:type="string">modulename</item>
            <item name="dataScope" xsi:type="string">redirect_external_url</item>
            <item name="visibleValue" xsi:type="string">1</item>
            <item name="visible" xsi:type="boolean">false</item>
            <item name="validation" xsi:type="array">
                <item name="required-entry" xsi:type="boolean">true</item>
                <item name="validate-url" xsi:type="boolean">true</item>
            </item>
        </item>
    </argument>
</field>
<field name="redirect_in">
    <argument name="data" xsi:type="array">
        <item name="options" xsi:type="object">Namespace\Modulename\Model\Config\Source\Options</item>
        <item name="config" xsi:type="array">
            <item name="dataType" xsi:type="string">int</item>
            <item name="label" xsi:type="string" translate="true">Store Info</item>
            <item name="component" xsi:type="string">Namespace_Modulename/js/form/element/options</item>
            <item name="formElement" xsi:type="string">select</item>
            <item name="source" xsi:type="string">modulename</item>
            <item name="dataScope" xsi:type="string">redirect_in</item>
            <item name="default" xsi:type="string">0</item>
            <item name="validation" xsi:type="array">
                <item name="required-entry" xsi:type="boolean">true</item>
            </item>
        </item>
    </argument>
</field>
| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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