skip to Main Content

Basically, I want to send ‘store’ as a parameter when I save the form. For this, I customized the save button and added store_id there, but now save method is called twice. Any idea why this is happening and how can I fix it?

This is the button:(VendorModuleBlockAdminhtmlEntityEditSaveButton.php)

public function getButtonData()
{
    return [
        'label' => __('Save'),
        'class' => 'save primary',
        'data_attribute' => [
            'mage-init' => [
                'buttonAdapter' => [
                    'actions' => [
                        [
                            'targetName' => 'vendor_module_entity_form.vendor_module_entity_form',
                            'actionName' => 'save',
                            'params' => [
                                true,
                                ['store' => 5]
                            ]
                        ]
                    ]
                ]
            ]
        ],
        'sort_order' => 90,
    ];
}

and this is the ui_component (vendor_entity_entity_form.xml):

......
<settings>
    <buttons>
        <button class="VendorModuleBlockAdminhtmlEntityEditSaveButton" name="save"/>
    </buttons>
</settings>
<dataSource name="entiity_form_data_source">
    <settings>
        <submitUrl path="*/*/save"/>
        <validateUrl path="*/*/validate"/>
    </settings>
</dataSource>
......

2

Answers


  1. Please try:

    public function getButtonData(): array
    {
        return [
            'label' => __('Save'),
            'class' => 'save primary',
            'data_attribute' => [
                'mage-init' => ['button' => ['event' => 'save']],
                'form-role' => 'save',
            ],
            'sort_order' => 10
        ];
    }
    
    Login or Signup to reply.
  2. 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]
                );
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search