I am using yii2mod/yii2-sweet-alert in my projects, I am using it on basic and advanced themes, and I love it.
The question. How can I change the grid default confirmation dialog that is a plain javascript confirmation in order to use Sweet-alert to make it look better?
I already tried modifying the button's template for the delete, because if you want to change the message you will do the following:
[
'class' => ActionColumn::className(),
'template' => '{update}{delete}',
'buttons' => [
'delete' => function($url, $model){
return Html::a('<span class="glyphicon glyphicon-trash"></span>', ['delete', 'id' => $model->id], [
'class' => '',
'data' => [
'confirm' => 'Are you absolutely sure ? You will lose all the information about this user with this action.',
'method' => 'post',
],
]);
}
]
]
But I haven't been successful on changing the confirmation message from the javascript one to sweet alert.
Also I am trying as a second option, to make it work with Krajee/ Grid and actionColumn but still can make it work «this is the second option am working, to do this».
[
'class' => 'kartik\grid\ActionColumn',
'viewOptions' => ['hidden' => true],
'updateOptions' => ['title' => 'Edit events', 'data-toggle' => '??'],
'deleteOptions' => ['title' => 'delete your event', 'data-toggle' => 'I am Lost here'],
],
Please any idea on how to change this behavior?
MORE ON HOW TO SOLVE IT - thanks to @muhammad-omer-aslam
create a js file on your public folder, in my case
/backend/web/js/confirmSwal.js
and add the provided code:Add these lines
yii.confirm = function (message, okCallback, cancelCallback) { swal({ title: message, type: 'warning', showCancelButton: true, closeOnConfirm: true, allowOutsideClick: true }, okCallback); };
Add this to your AppAssets on
/backend/assets/AppAssets.php
public $js = [ '/js/confirmSwal.js', ];
And that's it it works beautiful.
Thanks again to Muhammad.