Skip to content

Columns in AbstractFieldArray subclasses do not get their ID set correctly #22008

Open
@Berdir

Description

@Berdir

Preconditions (*)

  1. 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.

Metadata

Metadata

Assignees

Labels

Area: ContentIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedPriority: P3May be fixed according to the position in the backlog.Progress: PR in progressReproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branchSeverity: S3Affects non-critical data or functionality and does not force users to employ a workaround.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions