1

I experienced a situation were I added additional fields in the backend customer form and these were not posted with the request. The fields were neither available in the observer using the $observer->getRequest()->getPostValue() methods neither they were showing as sent along with the request when debugging the request using Chrome Developer Tools under the network tab. All data except these custom fields was sent as it should. It seemed like the javascript class responsible for submitting the form data was ignoring any custom fields.

1 Answer 1

5

By browsing the following javascript file:

magento/vendor/magento/module-ui/view/base/web/js/form/form.js

I noticed that the submit function was retrieving additional fields using a specific html attribute.

On line 197 the selector is set as follow:

this.selector = '[data-form-part=' + this.namespace + ']';

Solution:

We have to add this specific data-form-part attribute to the field declaration with the form name as value in order for the field to be "selected" by the form.js UI script. Then all posted values will be available as part of the POST request along with the initial fields.

Example:

$fieldset->addField('some_input', 'text',
    [
        'name' => 'some_input',
        'label' => __('Some Input'),
        'title' => __('Some Input'),
        'required' => true,
        'data-form-part' => 'customer_form' //SET THIS ATTRIBUTE
    ]

This solution should also be applicable to other Magento forms once we changed the customer_form value to the name of the form we are willing to add fields to.

1
  • 1
    How can i achieve same thing using UI-component? Jan 28, 2019 at 12:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.