Default Confirm In Cgridview

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)

                                            }',

                        ),

            //

                    ),

                ),

                

            ),

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;

btw, the better way is to hold defined confrm message:


bootbox.confirm("{$this->deleteConfirmation}", function(result) {