1

I want to pass a value/params via the save button of my ui adminform.

i tried this:

public function getButtonData()
    {
        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $request = $objectManager->get('Magento\Framework\App\RequestInterface');
        $id = $request->getParam('id');

        return
            [
                'label' => __('Save'),
                'class' => 'save primary',
                'on_click' => '',
                'sort_order' => 80,
                'data_attribute' => [
                    'mage-init' => [
                        'Magento_Ui/js/form/button-adapter' => [
                            'actions' => [
                                [
                                    'targetName' => 'thechateau_magenest_bookable_save',
                                    'actionName' => 'save',
                                    'params' => [
                                        true,
                                        ['multidome_id' =>$id],
                                    ]
                                ]
                            ]
                        ]
                    ],

                ]
            ];
    }

I can indeed see the values in the save button of the phtml page.

<button id="save" title="Save" type="button" class="action- scalable save primary" data-mage-init="{&quot;Magento_Ui\/js\/form\/button-adapter&quot;:{&quot;actions&quot;:[{&quot;targetName&quot;:&quot;thechateau_magenest_bookable_save&quot;,&quot;actionName&quot;:&quot;save&quot;,&quot;params&quot;:[true,{&quot;multidome_id&quot;:&quot;1&quot;}]}]}}"  data-ui-id="save-button" >
    <span>Save</span>
</button>

however when i try to retreive these values it comes up null.

$request = $this->_objectManager->create('Magento\Framework\App\RequestInterface');


$multiDome = $request->getParam('multidome_id');

I also tried to add it as part of the URL of the save button but it does not even show up on this:

public function getSaveUrl()
    {
        return $this->getUrl('*/*/save',['param'=>'value']);

    }
theSeeker
  • 297
  • 4
  • 12

1 Answers1

1

You can add any parameter to the submit URL. It can be useful to handle some cases in your's controller. There is example of "Save" button.

public function getButtonData()
{
    return
        [
            'label' => __('Save'),
            'class' => 'save primary',
            'on_click' => '',
            'sort_order' => 10,
            'data_attribute' => [
                'mage-init' => [
                    'Magento_Ui/js/form/button-adapter' => [
                        'actions' => [
                            [
                                'targetName' => 'your_custom_form_or_listing_name.your_custom_form_or_listing_name',
                                'actionName' => 'save',
                                'params' => [
                                    true,
                                    ['custom_param' => 'qwerty123456'],
                                ]
                            ]
                        ]
                    ]
                ],

            ]
        ];
}

You can change "Save and Continue Edit" button as well. Only don't forget to add to 'params' param 'back'. There is example of "Save and Continue Edit" button.

public function getButtonData()
{
    return
        [
            'label' => __('Save and Continue Edit'),
            'class' => 'save',
            'on_click' => '',
            'sort_order' => 20,
            'data_attribute' => [
                'mage-init' => [
                    'Magento_Ui/js/form/button-adapter' => [
                        'actions' => [
                            [
                                'targetName' => 'your_custom_form_or_listing_name.your_custom_form_or_listing_name',
                                'actionName' => 'save',
                                'params' => [
                                    true,
                                    [
                                        'back' => 1,
                                        'custom_param' => 'qwerty123456',
                                    ]
                                ]
                            ]
                        ]
                    ]
                ],

            ]
        ];
}