mahdi1986
(M Shirinabadi)
July 16, 2013, 8:05am
1
Hi dears,
when i create admin page with CRUD,Cgridview have button for delete row, i want to change confirm message to bootbox confirm message in extende Class, I overrid method
and I change this code
if(is_string($this->deleteConfirmation))
{
$confirmation="if(!confirm(".CJavaScript::encode($this->deleteConfirmation).")) return false;";
}
to
if(is_string($this->deleteConfirmation))
{
$confirmation="if(!bootbox.confirm(".CJavaScript::encode($this->deleteConfirmation).")) return false;";
}
But,This confirm now work, and when confirm message appear,immediately delete row and don’t waiting for confirm box,
Please help me
'buttons' => array('delete' =>
array(
'url' => 'Yii::app()->controller->createUrl("delete",array("id"=>$data->primaryKey))',
'label' => 'delete',
'options' => array(// this is the 'html' array but we specify the 'ajax' element
'confirm' => $alert,
'class' => 'grid_action_set1',
//if call ajax
'ajax' => array(
'type' => 'POST',
'url' => "js:$(this).attr('href')", // ajax post will use 'url' specified above
'success' => 'function(data){
alert(data)
}',
),
//
),
),
),
mahdi1986
(M Shirinabadi)
July 16, 2013, 8:25am
3
'buttons' => array('delete' =>
array(
'url' => 'Yii::app()->controller->createUrl("delete",array("id"=>$data->primaryKey))',
'label' => 'delete',
'options' => array(// this is the 'html' array but we specify the 'ajax' element
'confirm' => $alert,
'class' => 'grid_action_set1',
//if call ajax
'ajax' => array(
'type' => 'POST',
'url' => "js:$(this).attr('href')", // ajax post will use 'url' specified above
'success' => 'function(data){
alert(data)
}',
),
//
),
),
),
thanks for replay, where I use bootbox.confirm?
you can use the click function
$("a.grid_action_set1").click(function(e) {
e.preventDefault();
bootbox.confirm("Are you sure?", function(confirmed) {
console.log("Confirmed: "+confirmed);
});
});
Hi
you can see the more detail…
http://bootboxjs.com/
hope it’s will be help…
Hi,
I implemented this. The thing is that the ajax has to be executed in the bootbox success function
In CButtonColumn.php override $this->buttons[‘delete’][‘click’] with the following value:
//bootbox confirmation
$this->buttons['delete']['click']=<<<EOD
function() {
var th = this;
var href = $(this).attr('href');
afterDelete = $this->afterDelete;
bootbox.confirm("Are you sure?", function(result) {
if(result){
jQuery('#{$this->grid->id}').yiiGridView('update', {
type: 'POST',
url: href,$csrf
success: function(data) {
jQuery('#{$this->grid->id}').yiiGridView('update');
afterDelete(th, true, data);
},
error: function(XHR) {
return afterDelete(th, false, XHR);
}
});
}
});
return false;
}
EOD;
someone
(198506)
April 10, 2014, 7:14am
7
btw, the better way is to hold defined confrm message:
bootbox.confirm("{$this->deleteConfirmation}", function(result) {