0

I have an XML form on the backend. It has the save button the code for which is this -

class SaveButton implements \Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface {

public function __construct(
    \Magento\Backend\Block\Widget\Context $context,
    \Magento\Framework\UrlInterface $urlInterface,
    \Magento\Framework\App\RequestInterface $request
) {
    $this->urlBuilder = $context->getUrlBuilder();
    $this->urlInterface = $urlInterface;
    $this->request = $request;
}

public function getButtonData()
{

    $productId = $this->request->getParam('id');

    return [
        'label' => __('Save'),
        'class' => 'save primary',
         'data_attribute' => [
             'mage-init' => ['button' => ['event' => 'save']],
             'form-role' => 'save',
         ],
        'onclick' => $this->urlBuilder->getUrl( '{moduleName}/{controllerName}/save','product_id' => $productId ] ),
        'sort_order' => 90,
    ];
}

When I click on save, it just reloads the page and doesn't take the control to the save controller.

Thanks!

1

Remove onclick parameter from the array. So looks like:

return [
    'label' => __('Save'),
    'class' => 'save primary',
     'data_attribute' => [
         'mage-init' => ['button' => ['event' => 'save']],
         'form-role' => 'save',
     ],
    'sort_order' => 90,
];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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