Description
Preconditions (*)
- Magento 2.3.1
Steps to reproduce (*)
Create a subclass of AbstractFieldArray and include at least one custom renderer to display a select element with options. Optionally a regular column with a standard textfield. Store some values.
Expected result (*)
Both the textfield and the select should have their previously stored default value set.
Actual result (*)
Only the textfield has a default value. People are doing strange workarounds through _prepareArrayRow, like in https://magento.stackexchange.com/questions/202208/how-to-properly-load-config-table-data-into-admin-panel with extra option attributes, but the source of the problem seems to be that the select has an empty ID attribute, bucause no 'id' is passed to the renderer. Instead a 'input_id' data key is passed in, but not used:
<select name="groups[yellowcube][fields][allowed_methods][value][_1553583037209_209][allowed_methods]" id=""
I was able to fix this by passing the id through $attributes, and then it just worked:
$this->_methodRenderer = $this->getLayout()->createBlock(
Codes::class,
'',
[
'is_render_to_js_template' => true,
'data' => [
'id' => $this->_getCellInputElementId('<%- _id %>', 'allowed_methods'),
],
]
);
Results in:
<select name="groups[yellowcube][fields][allowed_methods][value][_1553583037209_209][allowed_methods]" id="_1553583037209_209_allowed_methods"
I think this should be done by default, similar to how the input name is set.
This happens in \Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray::renderCellTemplate(), where it sets the name and input id, but the InputId is a non-unused attribute, that should be Id instead.