I have so many fields in my admin grid form which made using UI component. I want to hide some of the fields using php condition. I know that it can done using DataProvider file and I also followed this thread Disabling a UI component field upon condition in Magento 2.

But it didn't work for me. Did any one has done this before having any idea/solution apart from this?

Please guide. That would be really handy.


  • could you please post your code. Sep 7, 2018 at 9:15
  • @DharmendraJadav. Thanks for your quick response. I won't mind pasting code here but it is similar to the one which is written in the reference thread. There are many fields in admin grid form and I want to hide few based on php condition. Still, if you want then I'll paste my code of the specific file which you want to see. Let me know. Thanks. Sep 7, 2018 at 9:20

2 Answers 2


Override getMeta function in your dataprovider and set value like this.

my form.xml

    <fieldset name="fieldset_name">            
            <field name="attribute_id">
                <argument name="data" xsi:type="array">
                    <item name="options" xsi:type="object">Vendor\Module\Model\Source\Attributes</item>
                    <item name="config" xsi:type="array">
                        <item name="dataType" xsi:type="string">text</item>
                        <item name="formElement" xsi:type="string">select</item>
                        <item name="label" xsi:type="string" translate="true">Attribute</item>
                        <item name="component" xsi:type="string">Vendor_Module/js/form/element/select-option</item>                    
                        <item name="dataScope" xsi:type="string">attribute_id</item>
                        <item name="componentType" xsi:type="string">select</item>
                        <item name="validation" xsi:type="array">
                            <item name="required-entry" xsi:type="boolean">true</item>

My DataProvide.

public function getMeta()
        $meta = parent::getMeta();
        $id = $this->request->getParam('id');
        if(<<Your Condition>>){

            $meta['fieldset_name']['children']['attribute_id']['arguments']['data']['config']['disabled'] = 1;
        return $meta;

I have disable form field using this. It's work fine. you can try.

If you still any query let me know.

  • Hello @Dharmendra. You are a life saver. This solution worked like a charm. Not fully but I just wanted some hint and I got it from your code. I have just changed a little bit in getMeta() function. I have used ['visible'] = 1 or 0 instead of ['disabled']. Thanks a lot. Sep 7, 2018 at 9:56
  • "I have used ['visible'] = 1 or 0 instead of ['disabled']", That's why i am asking about the code. Sep 7, 2018 at 10:00
  • Hello @Dharmendra. I think you just misunderstood me. Earlier, I have not used code which you posted recently. I just informed you that I have used visible property in the code you provided. Otherwise, your code works fine. Cheers! Sep 7, 2018 at 10:03
  • I am getting empty array when print meta in this fuction Sep 25, 2020 at 9:23
  • @DharmendraJadav can you please answer this magento.stackexchange.com/questions/328895/…
    – amith lal
    Jan 6, 2021 at 1:20

I have a disabled fieldset in add new form based on entity_id

add the following code in your data provider class

public function getMeta()
        $meta = parent::getMeta();
        $id = $this->request->getParam('entity_id');

           $meta['fieldset_name']['arguments']['data']['config']['visible'] = 1;

           $meta['fieldset_name']['arguments']['data']['config']['visible'] = 0;

        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.