5

I have created custom admin grid,I wish to add confirmation alert popup while clicking my custom field (like before deleting,before update status).Please provide me a solution

I need to show the confirm alert like below

enter image description here

  • if you got this please reply here. – sumeet bajaj May 1 '19 at 10:38
  • are you trying to add a message in massaction or columnaction? – Ghulam.M May 2 '19 at 13:34
  • Try with a given answer and let me know if you have any query. – Chirag Patel May 2 '19 at 13:48
  • Have you got solution? – Chirag Patel May 9 '19 at 4:31
0

If you are trying to show on MASS DELETE you can add a message item.

        <massaction name="listing_massaction">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="selectProvider" xsi:type="string">
                    your_listing.your_listing.your_index_columns.ids
                </item>
                <item name="indexField" xsi:type="string">topic_id</item>
            </item>
        </argument>
        <action name="delete">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="type" xsi:type="string">delete</item>
                    <item name="label" xsi:type="string" translate="true">Delete</item>
                    <item name="url" xsi:type="url" path="route/controler/massDelete"/>
                    <item name="confirm" xsi:type="array">
                        <item name="title" xsi:type="string" translate="true">Delete items</item>
                        <item name="message" xsi:type="string" translate="true">Are you sure you wan't to delete
                            selected items?
                        </item>
                    </item>
                </item>
            </argument>
        </action>
    </massaction>
| improve this answer | |
0

Let's explain with an example :

If you want to add an alert message in admin Form:

ui/test_form.xml

<settings>
    <buttons>
        <button class="Namespace\Modulename\Block\Adminhtml\Label\Edit\DeleteButton" name="delete"/>
    </buttons>                
</settings>

app/code/Namespace/Modulename/Block/Adminhtml/Label/Edit/DeleteButton.php

<?php
namespace Namespace\Modulename\Block\Adminhtml\Productlabel\Edit;

use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;

class DeleteButton extends GenericButton implements ButtonProviderInterface
{

    /**
     * @return array
     */
    public function getButtonData()
    {
        $data = [];
        if ($this->getModelId()) {
            $data = [
                'label' => __('Delete'),
                'class' => 'delete',
                'on_click' => 'deleteConfirm(\'' . __(
                    'Are you sure you want to do this?'
                ) . '\', \'' . $this->getDeleteUrl() . '\')',
                'sort_order' => 20,
            ];
        }
        return $data;
    }

    /**
     * Get URL for delete button
     *
     * @return string
     */
    public function getDeleteUrl()
    {
        return $this->getUrl('*/*/delete', ['id' => $this->getModelId()]);
    }
}

You can also do it for all action just pass your block file path to under <setting> node in your form.xml and create block file same as given above.

Display alert message in grid Mass Action:

If you want to display a message in mass action in a grid listing then like below :

<action name="delete">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="type" xsi:type="string">delete</item>
                    <item name="label" xsi:type="string" translate="true">Delete</item>
                    <item name="url" xsi:type="url" path="routname/controler/massDelete" />
                    <item name="confirm" xsi:type="array">
                        <item name="title" xsi:type="string">Delete items</item>
                        <item name="message" xsi:type="string" translate="true">Are you sure you wan't to delete selected items?</item>
                    </item>
                </item>
            </argument>
        </action>

That's it! I hope it helps!

| improve this answer | |
  • Do you know about how to add custom URL for cancel button? – Rohan Hapani Jul 15 '19 at 12:35
0

In my case this worked, MagentoEE 2.2.6

<massaction name="listing_massaction" component="Magento_Ui/js/grid/tree-massactions">
    <action name="delete">
        <settings>
            <confirm>
                <message translate="true">Are you sure to delete selected items?</message>
                <title translate="true">Delete items</title>
            </confirm>
        </settings>
    </action>
</massaction>
| improve this answer | |

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.