0

I'm working on an admin ui form

https://github.com/DominicWatts/Announce/blob/hotfix/tabs/view/adminhtml/ui_component/xigen_announce_group_form.xml

I've added tabs

In order to get the tabs working I've removed the <item name="template" xsi:type="string">templates/form/collapsible</item> from the XML

My form elements have changed from <input name="name"> to <input name="general[name]">

Which makes sense

However when editing a record the form fields now appear blank. I've forgotten a step.

It's to do with dataScope and chaining

enter image description here

Any suggestion?

0

I overlooked this comment

The source node's value corresponds to a key in the data array returned by the \Magento\Framework\View\Element\UiComponent\DataProvider\DataProviderInterface::getData method of your UI component.

From https://magento.stackexchange.com/a/219692/70343

Sure enough


    /**
     * Get data
     * @return array
     */
    public function getData()
    {
        if (isset($this->loadedData)) {
            return $this->loadedData;
        }
        $items = $this->collection->getItems();
        foreach ($items as $model) {
            $this->loadedData[$model->getId()] = $model->getData();
            $this->loadedData[$model->getId()]['general'] = $model->getData();  // key part
        }
        $data = $this->dataPersistor->get('xigen_announce_group');

        if (!empty($data)) {
            $model = $this->collection->getNewEmptyItem();
            $model->setData($data);
            $this->loadedData[$model->getId()] = $model->getData();
            $this->loadedData[$model->getId()]['general'] = $model->getData(); // key part
            $this->dataPersistor->clear('xigen_announce_group');
        }

        return $this->loadedData;
    }

Helped to look at this https://github.com/magento/magento2/blob/2.3/app/code/Magento/Customer/Model/Customer/DataProvider.php#L214-L252

I hope this helps someone. Might save them an hour.

| improve this answer | |

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.