Revision #2 has been created by Cozumel on Feb 23, 2016, 4:30:00 PM with the memo:
Added example with bootbox title
« previous (#1)
Changes
Title
unchanged
Escape from Default's Yii2 Delete Confirm Box
Category
unchanged
How-tos
Yii version
unchanged
Tags
unchanged
yii2, bootstrap, gridview
Content
changed
[...]
});
// confirm will always return false on the first call
// to cancel click handler
return false;
}
```
Bootbox confirm by default doesn't have a title, to add a title (modal-title) to your confirm box, use this code instead:
```php
yii.allowAction = function ($e) {
var message = $e.data('confirm');
return message === undefined || yii.confirm(message, $e);
};
yii.confirm = function (message, $e) {
bootbox.confirm({
title: 'Confirm',
message: 'Are you sure?',
callback: function (result) {
if (result) {
yii.handleAction($e);
}
}
});
// confirm will always return false on the first call
// to cancel click handler
return false;
}
```
The way the module comes by default is by using the native browser's confirm dialog window that obviously stops the asynchronous execution of Javascript, but when you try to use "<strong>bootbox::confirm</strong>" method, that is not happening as the callback of the plugin does not return until the user clicks on one of the dialog's buttons.
Thats the reason we override the "<strong>yii::confirm</strong>", because we require the reference of the DOM object in order to call "<strong>yii::handleAction</strong>" properly. But is "<strong>yii::allowAction</strong>" the method who receives that reference, and thats why we had to override that method as well.[...]