How to trigger Yii2 Confirm Dialog

yii2 gridview delete confirm
yii submit button confirm
confirm box in php with yes no option
jquery confirm
yii2 attribute encode
html :: error yii2
javascript confirm
yii2 delete confirmation

I have a custom ActionColumn on GridView and trying to call yii.confirm function using data-confirm for delete action but the dialog not shown.

[
'format'=>'html',
'content'=>function($data) {
    $btn = ButtonDropdown::widget([
    'label' => 'Action',
    'options' => ['class'=>'btn btn-sm btn-primary dropdown-toggle', 'type'=>'button'],
    'dropdown' => [
        'options' => ['class'=>'dropdown-menu action', 'role'=>'menu'],
        'items' => [
            '<li><a href="'.Url::to(['details','id'=>$data->id]) .'"><i class="fa fa-pencil"></i> Details</a></li>',
            '<li><a href="'. Url::to(['edit', 'id' => $data->id]) .'"><i class="fa fa-eye"></i> Edit</a></li>',
            '<li role="presentation" class="divider"></li>',
            '<li><a data-method="post" data-confirm="Are you sure ?" href="'.Url::to(['delete', 'id' => $data->id]).'"><i class="fa fa-trash"></i> Delete</a></li>',                                                
        ],
    ],
]);
return $btn;
},
],

But when I'm trying to add link without dropdown it works

[
'format'=>'html',//raw, html
    'content'=>function($data) {
        $btn ='<a data-method="post" data-confirm="Are you sure ?" href="'.Url::to(['delete', 'id' => $data->id]).'"><i class="fa   fa-trash"></i> Delete</a>';                                                
        return $btn;
    },
],

You can add a link like this

    <?php echo Html::a(Yii::t('backend', 'Delete'), ['delete', 'id' => $model->id], [
        'class' => 'btn btn-danger',
        'data' => [
            'confirm' => Yii::t('backend', 'Are you sure you want to delete this item?'),
            'method' => 'post',
        ],
    ]) ?>

How to trigger Yii2 Confirm Dialog, Escape from Default's Yii2 Delete Confirm Box certain javascript behaviors like for example, its delete confirmation dialog box. but when I click 'ok', the page refreshes, but it should trigger pjax reload, how can I do this? But it would be better if it can be changed to use the confirm dialog with bootstrap style. Since Yii2 is already integrated with the bootstrap widget. In this tutorial, I will share how I implement the new confirm dialog with a translated message by Yii::t(). Here what we will do. Download the bootboxjs which is a small javascript library. It allows you to create programmatic dialog boxes using Bootstrap modals.

I should use linkOtions form Items

     [
    'format'=>'html',
    'content'=>function($data) {
        $btn = ButtonDropdown::widget([
        'label' => 'Action',
        'options' => ['class'=>'btn btn-sm btn-primary dropdown-toggle', 'type'=>'button'],
        'dropdown' => [
            'options' => ['class'=>'dropdown-menu action', 'role'=>'menu'],
            'items' => [
              ['label' => 'Details', 'url' =>  ['details','id'=>$data->id], 
                      'linkOptions' => ['class'=>'fa fa-pencil'],],
              ['label' => 'Edit', 'url' =>  ['edit','id'=>$data->id], 
                      'linkOptions' => ['class'=>'fa fa-eye'],],
              ['label' => '<span role="presentation" class="divider"></span>'],
              ['label' => 'Delete', 'url' =>  ['delete','id'=>$data->id], 
                      'linkOptions' => ['class'=>'fa fa-trash' , 'data' => [
                    'confirm' => 'Are you sure ?',
                    'method' => 'post',
                ]],],                 
            ],
        ],
    ]);
    return $btn;
  },
  ],

Escape from Default's Yii2 Delete Confirm Box | Wiki, I have the same issue after updating yii2 to 2.0.10. Found, that the problem is in yii.activeForm.js and in this line data.submitObject.trigger("click  Overriding Yii's Confirmation Dialog. Yii renders the native confirmation dialog on links that are rendered by setting data-confirm property on links. This widget enhances and beautifies the native confirmation dialog using Krajee Dialog. This behavior can be controlled via the overrideYiiConfirm property which defaults to true. This can be

That's because you are using 'format'=>'html' option. The html formatter uses HTMLPurifier, that get rid of data attributes.

Use 'format'=>'raw' instead.

Confirm dialog on submit button is fired twice, If the button is placed , Don't should by generated a confirm dialog What do you get instead? dialog. https://github.com/yiisoft/yii2/blob/master/framework/assets/yii.js#L475 if $​confirmation is false (or null may be), do not trigger confirm dialog. To create custom dialog for yii.confirm, current design is so inconvenient. JSe&#39;s standard confirm() function can block event handling until user input. But most of custom modal UI (for example

Html::a data-confirm => false for disabled confirm dialog · Issue , You can add a link like this <?php echo Html::a(Yii::t('backend', 'Delete'), ['delete', 'id' => $model->id], [ 'class' => 'btn btn-danger', 'data'  Confirm dialog on submit button is fired twice, If the button is placed in the form #13255. Confirm dialog on submit button is fired twice, If the button is placed in the form. #13255.

How to trigger Yii2 Confirm Dialog, ALERT dialog. CONFIRM dialog. PROMPT dialog. CUSTOM dialog. Includes a jQuery plugin krajeeDialog (created by Krajee)  This is a tricky issue. It happens when data-confirmis used for a submit button in an active form. The first confirm dialog is triggered by the click handler of the button. The second is triggered by active form when validation succeeds (Line 501, $button.click()). Not sure how to fix this issue.

Dialog - © Kartik, In Yii 2, the grid view widget and default view of a model provide the delete button that uses the window confirmation dialog. Offering simple  The confirm() method displays a dialog box with a specified message, along with an OK and a Cancel button. A confirm box is often used if you want the user to verify or accept something. Note: The confirm box takes the focus away from the current window, and forces the browser to read the message.

Comments
  • Hi thanks for the improvement, but the confirmation dialog still not appears
  • Please show the all the code of actioncolumn section in grdiview .. the part you show in notb enough for a better evaluation..
  • The solution does work if you remove the square brackets surrounding the data confirm array, so it's: 'data' => [ 'confirm' => 'Are you sure ?', 'method' => 'post', ]