1

I am working on the custom extension and I need delete button in the custom form at the backend. When I edit a record, there should be delete button above with other buttons like Back, Reset and Save and continue edit. Please see the screenshot to get more idea. Can someone guide me for it?

enter image description here

1
  • can you show the code from your Edit.php block file? Commented Jun 22, 2016 at 11:09

1 Answer 1

6

Add below code in app\code\Vendor\ModuleName\Block\Adminhtml\Module\Edit.php in _construct()

protected function _construct(){
        $this->addButton(
            'delete',
            [
                'label' => __('Delete'),
                'onclick' => 'deleteConfirm(' . json_encode(__('Are you sure you want to do this?'))
                    . ','
                    . json_encode($this->getDeleteUrl()
                    )
                    . ')',
                'class' => 'scalable delete',
                'level' => -1
            ]
        );
}

Below will be your delete action.

/**
 * @param array $args
 * @return string
 */
public function getDeleteUrl(array $args = [])
{
    $params = array_merge($this->getDefaultUrlParams(), $args);
    return $this->getUrl('module/*/delete', $params);
}
2
  • 3
    I have done minor change to make it work, public function getDeleteUrl(array $args = []) { return $this->getUrl('*/*/delete', ['_current' => true, 'back' => 'edit', 'active_tab' => '{{tab_id}}']); } Commented Jun 22, 2016 at 11:35
  • Hello @Ajay, I have also added delete button from your code, but it is also appearing for new form as well, so what condition will add to hide from new form? Commented Jul 7, 2017 at 9:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.