I have created custom field in Magento 2.4.1 product edit page,


<field name="type" formElement="select">
            <argument name="data" xsi:type="array">
                <item name="options" xsi:type="object">Ceymox\DigitalCard\Model\DigitalCard\Options</item>
                <item name="config" xsi:type="array">
                    <item name="source" xsi:type="string">block</item>
                <label translate="true">Digital Card Type</label>

        <file name="csv_uploader" >
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="label" xsi:type="string">CSV File</item>
                    <item name="visible" xsi:type="boolean">true</item>
                    <item name="formElement" xsi:type="string">fileUploader</item>
                    <item name="componentType" xsi:type="string">fileUploader</item> 
                    <item name="notice" xsi:type="string" translate="true">Allowed file type: csv.</item>
                    <item name="allowedExtensions" xsi:type="string">csv</item>
                    <item name="uploaderConfig" xsi:type="array">
                        <item name="url" xsi:type="url" path="digitalcard/index/generate"/>
        <insertListing name="digitalcard_listing" >

Now I need to hide this field based on condition(based on product type).How can i do this? can anyone help me on this

2 Answers 2


Check this link for reference :-

How to Create Dependent Fields in Forms using Ui components- Magento2

  • This toggles visibility based on the value of another form element. The question is about using the product type to determine visibility.
    – snez
    Commented May 30, 2022 at 8:37

Magento combines the data from your product_form.xml file with any custom data in you modifier class. What the Magento docs are not very clear about is the merging order. Magento uses whatever your modifyMeta() method returns to override the config from product_form.xml. This means that you can do the following:

public function __construct(
    \Magento\Catalog\Model\Locator\LocatorInterface $locator
    $this->locator = $locator;

public function modifyMeta(array $meta): array
    $product = $this->locator->getProduct();

    if ($product->getTypeId() != "configurable")
        $meta['your-group-id']['children']['your_field_id']['arguments']['data']['config'] = [
            "componentType" => "fieldset",
            "collapsible" => false,
            "sortOrder" => 1,
            'opened' => false,
            'canShow' => false,
            'visible' => false

    return $meta;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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