The ui form component works good on "New" action but, if I save this:
Then, the edit action shows this:
The data is being saved correctly in my custom table after submitting the "New" action.
Here is the dynamicRows
section of my ui form layout:
<container name="attribute_code_container">
<dynamicRows name="attribute_code">
<settings>
<componentType>dynamicRows</componentType>
<label translate="true">Attributes / Fields</label>
<columnsHeader>false</columnsHeader>
<addButton>true</addButton>
<addButtonLabel translate="true">Add attribute</addButtonLabel>
<deleteProperty>false</deleteProperty>
<dndConfig>
<param name="enabled" xsi:type="boolean">false</param>
</dndConfig>
</settings>
<container name="record" component="Magento_Ui/js/dynamic-rows/record">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="isTemplate" xsi:type="boolean">true</item>
<item name="is_collection" xsi:type="boolean">true</item>
<item name="componentType" xsi:type="string">container</item>
</item>
</argument>
<field name="attribute_code" formElement="select">
<formElements>
<select>
<settings>
<options class="Vendor\Module\Model\Source\Attribute"/>
</settings>
</select>
</formElements>
</field>
<actionDelete>
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="componentType" xsi:type="string">actionDelete</item>
<item name="dataType" xsi:type="string">text</item>
<item name="label" xsi:type="string">Delete</item>
<item name="template" xsi:type="string">Magento_Backend/dynamic-rows/cells/action-delete</item>
</item>
</argument>
</actionDelete>
</container>
</dynamicRows>
</container>
The Vendor\Module\Model\Source\Attribute
class seems to be OK,try with Magento\Config\Model\Config\Source\Yesno
(For example) I get the same result.
What is wrong with the dynamicRows
component and how can I set an instruction to get the data from my custom table the right way?
Best Answer
The layout XML of the dynamicGrid was OK but, because of using a select/option element to show the data, it was expecting an ARRAY and I was providing a string on my
dataSource
.Unserializing the data returned by my database made the trick:
Where
$this->serializerJson
is an object of\Magento\Framework\Serialize\Serializer\Json
.If you have similar issues, the thing you have to double-check is the implementation of your
dataSource
.