Skip to content

Website/Group/Store entity form can't be extended with multiple value form element for extension attributes #24070

Closed
@ericclaeren

Description

@ericclaeren

Summary (*)

When extending the Website/Group/Store form (module-backend/Block/System/Store/Edit/AbstractForm.php) with the adminhtml_store_edit_form_prepare_form event, multiple value fields (arrays) are being flattened by the javascript store validator (module-backend/view/adminhtml/web/js/validate-store.js). Preventing me to extend this form with a multiselect, checkboxes or radios form element.

Examples (*)

  1. Create Observer for adminhtml_store_edit_form_prepare_form
  2. Add field with multiselect.
    /**
     * @param Observer $observer
     */
    public function execute(Observer $observer): void
    {
        $block = $observer->getEvent()->getBlock();
        $form = $block->getForm();
        $fieldSettings = [
            'name' => 'store[multiple][]',
            'label' => __('Multiselect field'),
            'value' => '',
            'values' => [
            ],
            'required' => false,
            'disabled' => false,
        ];

        $fieldset = $form->addFieldset('group_multiselect', ['legend' => __('Multiselect fieldset')]);
        $fieldset->addField('multiselectElement', 'multiselect', $fieldSettings);
        $observer->setData('block', $block->setForm($form));
    }
  1. Save form and check headers of postdata.

Proposed solution

Remove the each callback on serializeArray which sets the name of the formData element to a singular value or only apply the filter on the initial elements.

$.each($(form).serializeArray(), function () {
    formData[this.name] = this.value || '';
});

EDIT:

The proposed solution does not work, there can only be a single fieldname because it's converted to an object, which in turn, turns into a new form, with input name/value fields and that is being posted. Why you want do such a thing on a perfectly formatted html form, I don't know. But this is how it works :(

There is no way to post multiple values for this form unless it's an direct post instead of this fake form post generation.

Will create a pull request and provide solution for this issue shortly.

Activity

m2-assistant

m2-assistant commented on Aug 8, 2019

@m2-assistant

Hi @ericclaeren. Thank you for your report.
To help us process this issue please make sure that you provided the following information:

  • Summary of the issue
    Information on your environment
    Steps to reproduce
    Expected and actual results

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento give me 2.3-develop instance - upcoming 2.3.x release

For more details, please, review the Magento Contributor Assistant documentation.

@ericclaeren do you confirm that you were able to reproduce the issue on vanilla Magento instance following steps to reproduce?

  • yes
    no

ericclaeren

ericclaeren commented on Aug 9, 2019

@ericclaeren
Author

Have found a way to fix this, will fork and create pull request for this issue. Need some help testing this, because I don't know how to add a multiple field to this form for a feature test.

added
Priority: P3May be fixed according to the position in the backlog.
Severity: S3Affects non-critical data or functionality and does not force users to employ a workaround.
on Jun 17, 2020
added
Progress: PR CreatedIndicates that Pull Request has been created to fix issue
and removed
Progress: PR CreatedIndicates that Pull Request has been created to fix issue
on Sep 24, 2020
added
Triage: Dev.ExperienceIssue related to Developer Experience and needs help with Triage to Confirm or Reject it
on Mar 6, 2024

17 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Area: FrameworkComponent: BackendIssue: 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 progressProgress: doneReported on 2.4.xIndicates original Magento version for the Issue report.Reproduced 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.Triage: Dev.ExperienceIssue related to Developer Experience and needs help with Triage to Confirm or Reject it

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Participants

    @sdzhepa@ericclaeren@VladimirZaets@magento-engcom-team@engcom-Bravo

    Issue actions

      Website/Group/Store entity form can't be extended with multiple value form element for extension attributes · Issue #24070 · magento/magento2