3

I am using same form for add and edit functionality. i want to 1 field in add action and 2 field in edit action like: in new action i just want to enter fistname but in edit action i want to edit firstname and lastname both. So is it possible using same form in ui-component?

5
2

First set:

<item name="disabled" xsi:type="string">${ $.provider }:data.do_we_hide_it</item>

Suppose Namespace\Modulename\Model\Notification\DataProvider is your data provider for UI:

<dataSource name="notification_edit_data_source">
    <argument name="dataProvider" xsi:type="configurableObject">
        <argument name="class" xsi:type="string">Namespace\Modulename\Model\Notification\DataProvider</argument>
        <argument name="name" xsi:type="string">notification_edit_data_source</argument>

Then in its getData function add the following lines:

public function getData(){
.....
.....
if(condition1)
    $this->loadedData[$entity_id]['do_we_hide_it'] = true;
else
    $this->loadedData[$entity_id]['do_we_hide_it'] = false;

See the core files

vendor/magento/module-catalog/view/adminhtml/ui_component/category_form.xml
line 377 and vendor/magento/module-catalog/Model/Category/DataProvider.php line 303 for an example.

11
  • Hi @ChiragPatel. I do this. But, It's not working. – Emipro Technologies Pvt. Ltd. May 7 '19 at 11:27
  • I want to disable element store vise so. – Emipro Technologies Pvt. Ltd. May 7 '19 at 11:27
  • I have not tried with store specific. but I think the same method is given above and change only public function getData() function – Chirag Patel May 7 '19 at 11:34
  • get current store & inside condition check store it might be work. Try and let me know if you face any error. – Chirag Patel May 7 '19 at 11:35
  • If else condition proper working. But, It's always disabled. – Emipro Technologies Pvt. Ltd. May 7 '19 at 11:42

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.