Description
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 (*)
- Create Observer for adminhtml_store_edit_form_prepare_form
- 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));
}
- 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 commentedon Aug 8, 2019
Hi @ericclaeren. Thank you for your report.
To help us process this issue please make sure that you provided the following information:
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 releaseFor 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?
ericclaeren commentedon Aug 9, 2019
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.
17 remaining items