Difference between #1 and #2 of
Escape from Default's Yii2 Delete Confirm Box

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.
[...]
4 1
16 followers
Viewed: 46 163 times
Version: 2.0
Category: How-tos
Written by: Antonio Ramirez
Last updated by: Cozumel
Created on: Apr 27, 2014
Last updated: 8 years ago
Update Article

Revisions

View all history