I have added one fieldset in my admin form and want to show it only in the edit form and not in add new form
How can I do this based on the condition?
Solved! Go to Solution.
I am sharing this solution if someone faces this issue in the future, as I have wasted much time on this.
I have added the ui component field in my form as follows
<fieldset name="campaign_information"> <argument name="data" xsi:type="array"> <item name="config" xsi:type="array"> <item name="label" xsi:type="string">Campaign Information</item> <item name="collapsible" xsi:type="boolean">true</item> </item> </argument> <field name="name"> <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">Campaign Name</item> <item name="formElement" xsi:type="string">input</item> <item name="source" xsi:type="string">campaign</item> <item name="sortOrder" xsi:type="number">10</item> <item name="dataScope" xsi:type="string">name</item> <item name="validation" xsi:type="array"> <item name="required-entry" xsi:type="boolean">true</item> </item> </item> </argument> </field> <fieldset>
You can disable the field as well as fieldset based on your requirement
You need to
to disable the whole fieldset add the following code in your Data provider class
public function getMeta() { $meta = parent::getMeta(); $id = $this->request->getParam('entity_id'); if(isset($id)){ $meta['campaign_information']['arguments']['data']['config']['visible'] = 1; } else{ $meta['campaign_information']['arguments']['data']['config']['visible'] = 0; } return $meta; }
to disable particular filed in the fieldset use below code
public function getMeta() { $meta = parent::getMeta(); $id = $this->request->getParam('entity_id'); if(isset($id)){ $meta['fieldset_name']['children']['field_name']['arguments']['data']['config']['visible'] = 1; } else{ $meta['fieldset_name']['children']['field_name']['arguments']['data']['config']['visible'] = 0; } return $meta; }
hope this can help you
Thanks
I am sharing this solution if someone faces this issue in the future, as I have wasted much time on this.
I have added the ui component field in my form as follows
<fieldset name="campaign_information"> <argument name="data" xsi:type="array"> <item name="config" xsi:type="array"> <item name="label" xsi:type="string">Campaign Information</item> <item name="collapsible" xsi:type="boolean">true</item> </item> </argument> <field name="name"> <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">Campaign Name</item> <item name="formElement" xsi:type="string">input</item> <item name="source" xsi:type="string">campaign</item> <item name="sortOrder" xsi:type="number">10</item> <item name="dataScope" xsi:type="string">name</item> <item name="validation" xsi:type="array"> <item name="required-entry" xsi:type="boolean">true</item> </item> </item> </argument> </field> <fieldset>
You can disable the field as well as fieldset based on your requirement
You need to
to disable the whole fieldset add the following code in your Data provider class
public function getMeta() { $meta = parent::getMeta(); $id = $this->request->getParam('entity_id'); if(isset($id)){ $meta['campaign_information']['arguments']['data']['config']['visible'] = 1; } else{ $meta['campaign_information']['arguments']['data']['config']['visible'] = 0; } return $meta; }
to disable particular filed in the fieldset use below code
public function getMeta() { $meta = parent::getMeta(); $id = $this->request->getParam('entity_id'); if(isset($id)){ $meta['fieldset_name']['children']['field_name']['arguments']['data']['config']['visible'] = 1; } else{ $meta['fieldset_name']['children']['field_name']['arguments']['data']['config']['visible'] = 0; } return $meta; }
hope this can help you
Thanks
I have created a file upload field by ui component but in field name is showing as array event_data[event_homepdf] where event_data is the fieldset how can i remove field set from file upload field name
<field name="event_homepdf"> <argument name="data" xsi:type="array"> <item name="config" xsi:type="array"> <item name="source" xsi:type="string">Event</item> <item name="label" xsi:type="string" translate="true">Home PDF</item> <item name="visible" xsi:type="boolean">true</item> <item name="formElement" xsi:type="string">fileUploader</item> <item name="elementTmpl" xsi:type="string">ui/form/element/uploader/uploader</item> <item name="previewTmpl" xsi:type="string">Magento_Catalog/image-preview</item> <item name="required" xsi:type="boolean">false</item> <item name="uploaderConfig" xsi:type="array"> <item name="url" xsi:type="url" path="eventmanager/event/upload"/> </item> </item> </argument> </field>