How to customize confirmation for delete action

Hello, I’m trying to customize the confirmation message for the delete action in a grid.
My goal is to have something like this: “Are you sure to delete the XXXX number 999?”
Where XXXX = model name and 999 = id of the model.
I can set the “data-confirm” in the “buttonOptions” property, but only with a fixed string, and it doesn’t accept a closure.
Does someone can help me? Thanks

Hi @yi_pepe;
Welcome back to yii community!

try using this code on ActionColumn Grid View, this is a button ‘delete’

 'delete' => function($url, $model) {
                    $options = [
                        'data-confirm' => 'YOUR_MESSAGE',
                        'data-method' => 'post',
                    ];
                    return Html::a('<i class="fa fa-trash" style="color: var(--danger);"></i>', $url, $options);
                }

Good.
In the last line I use the code from “ActionColumn.initDefaultButton” so it display the same as default.

$icon = Html::tag('span', '', ['class' => "glyphicon glyphicon-trash"]);
return Html::a($icon, $url, $options);

Thanks a lot.

Here you can use closure in your instance:

'delete' => function($url, $model) use ($var) {
       $options = [
              'data-confirm' => 'YOUR_MESSAGE',
                    'data-method' => 'post',
             ];
       return Html::a('<i class="fa fa-trash" style="color: var(--danger);"></i>', $url, $options);
 }

@leonenco

Yes, you can use closure to instanciate!