0

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']);

    }
0

Use "getOptions()" method to add custom params. One example:

/**
 * Retrieve options
 *
 * @return array
 */
protected function getOptions()
{
    $options[] = [
        'id_hard' => 'save_and_new',
        'label' => __('Save & New'),
        'data_attribute' => [
            'mage-init' => [
                'buttonAdapter' => [
                    'actions' => [
                        [
                            'targetName' => 'member_form.member_form',
                            'actionName' => 'save',
                            'params' => [
                                true,
                                [
                                    'back' => 'new'
                                ]
                            ]
                        ]
                    ]
                ]
            ]
        ],
    ];

    if (!$this->context->getRequestParam('popup')) {
        $options[] = [
            'label' => __('Save & Duplicate'),
            'id_hard' => 'save_and_duplicate',
            'data_attribute' => [
                'mage-init' => [
                    'buttonAdapter' => [
                        'actions' => [
                            [
                                'targetName' => 'member_form.member_form',
                                'actionName' => 'save',
                                'params' => [
                                    true,
                                    [
                                        'back' => 'duplicate'
                                    ]
                                ]
                            ]
                        ]
                    ]
                ]
            ],
        ];
    }

    $options[] = [
        'id_hard' => 'save_and_close',
        'label' => __('Save & Close'),
        'data_attribute' => [
            'mage-init' => [
                'buttonAdapter' => [
                    'actions' => [
                        [
                            'targetName' => 'member_form.member_form',
                            'actionName' => 'save',
                            'params' => [
                                true
                            ]
                        ]
                    ]
                ]
            ]
        ],
    ];

    return $options;
}
9
  • hi. thanks for answer. but how do i add this. do i just place it on the SAVE BUTTON PAGE?
    – theSeeker
    Aug 13 '19 at 9:27
  • yes, Add this function to savebutton file. Just after the method "getButtonData". Aug 13 '19 at 9:32
  • does not work. i tried using getParams to get values but it still return null. really grateful if you would help
    – theSeeker
    Aug 13 '19 at 10:06
  • Can you share your full code file. I will work on it and share with you the working code. Aug 13 '19 at 10:13
  • no problem. should we go into the chat so that i can share the code . i am not sure how to enter into a one on chat. do u know how to ?
    – theSeeker
    Aug 13 '19 at 10:17
0

In my case I used ButtonProviderInterface

namespace MyVendor\Logger\Block\Adminhtml\Log\Index;
use \Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;

class ImportButton implements ButtonProviderInterface
{
    public function getButtonData()
    {
        return [
            'label' => __('Import Log'),
            'class' => 'action-secondary',
            'data_attribute' => [
                'mage-init' => [
                    'Magento_Ui/js/form/button-adapter' => [
                        'actions' => [
                            [
                                'targetName' => 'logger_log_listing.logger_log_listing.import_modal',
                                'actionName' => 'openModal'
                            ],
                        ]
                    ]
                ]
            ],
            'on_click' => '',
            'sort_order' => 20
        ];
    }
}

While declaring my button on the listing xml file logger_log_listing.xml, like so :

<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<argument name="data" xsi:type="array">
...
</argument>
<settings>
        ...
        <buttons>
            <button name="add">
                ...
            </button>
            <button name="import" class="MyVendor\Logger\Block\Adminhtml\Log\Index\ImportButton"/>
        </buttons>
</settings>
<modal name="import_modal">
...
</modal>

PS: I don't know why but not using 'on_click' => '' resulted in redirection to base url (front page)

0

please try the below code.

$this->buttonList->add(
            'select_all',
            [
                'label' => __('Select All Rates and Save'),
                'class' => 'save',
                'onclick' => "jQuery('#testhidden').val(1)",
                'data_attribute' => [
                    'mage-init' => ['button' => ['event' => 'save', 'target' => '#edit_form']],

                ]
            ],
            10
        );

Create a hidden field in the form.php where fields are defined

$fieldset->addField(
                'testhidden',
                'hidden',
                ['name' => 'testhidden', 'value' => 0, 'no_span' => true]
            );

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.