1

How to create custom “Duplicate” buttons for Adminhtml Edit Form save custom module in Magento2.1 and save and saveandcontinue Functionally not change.

Now duplicate button already create and onclick use setLocation but i have from submit so please any idea how to use button event in magento 2.1

        $this->buttonList->add(
            'duplicate',
            [
                'class' => 'save',
                'label' => __('Duplicate'),
                'onclick' => 'setLocation("' . $duplicateUrl . '")'
            ],
            12 // sort order
        );
4

I have found solution :

=> Add this option at Construct

$this->_formScripts[] =  "function duplicate(url){

     jQuery(document).ready(function(){
                //var old_action = jQuery('#edit_form').attr('action');
                jQuery('#edit_form').attr('action', url);
                jQuery('#edit_form').submit();
     });  

}";

// duplicateUrl 

$duplicateUrl = $this->_urlBuilder->getUrl(
    'modulename/controller/action',
    [
        'id' => $this->getRequest()->getParam('id'),
    ]
);

//Custom Button

$this->buttonList->add(
        'duplicate',
        [
            'class' => 'save',
            'label' => __('Duplicate'),
            'onclick' => 'duplicate("' . $duplicateUrl . '")'
        ],

    );
0

=> Add this option at Construct

 $this->_formScripts[] = " function duplicate(url){
           $('edit_form').submit($('edit_form').action+url);
        }";

=> Custom Button

 $this->buttonList->add(
            'duplicate',
            [
                'class' => 'save',
                'label' => __('Duplicate'),
                'onclick' =>  'duplicate("' . $duplicateUrl . '")'
            ],
            12 // sort order
        );

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.