Skip to content

How To Reload Product Form When Custom Select Field Change

I am trying to develop a feature for product type changes in Magento 2 via Product Edit Form Page. I added the product type field as a custom field as a modifier via a virtual type like the one below;

<virtualType name="MagentoCatalogUiDataProviderProductFormModifierPool">
        <arguments>
            <argument name="modifiers" xsi:type="array">
                <item name="type_id" xsi:type="array">
                    <item name="class" xsi:type="string">ModuleNameUiDataProviderProductFormModifierTypeId</item>
                    <item name="sortOrder" xsi:type="number">10</item>
                </item>
            </argument>
        </arguments>
</virtualType>

I copied and changed *MagentoCatalogUiDataProviderProductFormModifierAttributeSet* as TypeId, so in the final when I change the select value for type_id from the product form I want to reload the product form page(like when I shift Attribute Set select value).

I have observed this behavior and I guess I found a clue about how Magento accomplish this. In */module-catalog/view/adminhtml/ui_component/product_form.xml:18* there is a line like reloadItem ;

.
.
    <settings>
        <reloadItem>product-details.attribute_set_id:value</reloadItem>
        .
        .
    </settings>
.
.

I guess this block accomplish the behavior, I tried to change like

    <settings>
        <reloadItem>product-details.attribute_set_id:value</reloadItem>
        <reloadItem>product-details.type_id:value</reloadItem>
    </settings>

and it didn’t work. I guess this area does not work with multiple reloadItem elements.

Any idea how I can accomplish that?