Confirmation Dialog Customization

Dear All,

Spent good amount of time on this but couldn’t find a solution

I am trying to use Jquery Confirmation Dialog box in place of Java script standard confirmation dialog box for my project

I googled and found below nice Jquery confirmation dialogues

http://labs.abeautifulsite.net/archived/jquery-alerts/demo/

My case I am having rows of data with delete option for each row . Clicking on the delete link asks for the confirmation and based on user input it deletes the row .

For that I am using below Java script code. It is Working perfect and no issues


"onclick"=>"if (

            !confirm('Are you sure?\\r\\nYou are going to unregister for this subject.')

              ) {     return      }

But now to use the above Jquery dialog I don’t find a way to implement exactly like above . Below is the code I tried


"onclick"=>"if (

            !jConfirm('Can you confirm this?', 'Confirmation Dialog', 

                 function(r) {

                               return r ; 

                              }

                      )

                ){    return     } "

But this didn’t help and I even tried some other possibilities too … But none of them helped . Could some one provide the correct way to handle the above case ?

Or if there are other dialog boxes that helps me for my case …

Thank You

Regards

Full code where I am calling this




  echo (

            CHtml::ajaxLink(

                   'Delete',

                    Yii::app()->createUrl("editcourses/removeCourse"),

                    array(

                            "type"=>"POST",

                            "data"=>array(

                                    "place_type"=>$courses[$i]['course_type'],

                                    "place_id"=>$course[$i]['course_code'],

                            ),

                            "success"=>'js:function(data){  }',

                    ),

                    array(

                            "onclick"=>"

                                if (!jConfirm('Can you confirm this?', 'Confirmation Dialog', function(r) {

                                    return r ; })){return} "

                    )

            )

    );

Hi,

jConfirm works okay if to put ajax request to callback function.


                    array(

                            "onclick"=>"

                                if (!jConfirm('Can you confirm this?', 'Confirmation Dialog', function(result) {

                                    if(result){

                                        jQuery.ajax({'type':'POST','data':{'place_type':'TYPE','place_id':'CODE'},'success':function(data){ },'url':'/index.php/editcourses/removeCourse','cache':false}); 

                                    }

                                })){return }"

                    )



I didn’t dig deeper yet (maybe later) for the best solution in such a case, but hope it’ll give you a direction.

Hi yugene,

Thanks a lot for this solution . I just tried it and for my surprise the below code always getting me into success function( for wrong POST URL or right POST URL) and in success method if I print the data , It is HTML page of localhost WAMP server default page ( So it is not calling the desired URL whatever we want). Even I tried link instead of AjaxLink , But even that behaved the same . The data values I am posting to the URL are proper values , I tried alerting them and they printed fine . But not sure why always getting the success method and that too printing the Local Host page . any ideas?


   CHtml::ajaxLink(

                            CHtml::image(

                               'Delete','','' ,

                            array(

                                     "onclick"=>"                                         

                                            var parObj=$(this).parent().parent();

                                            if (!jConfirm('Can you confirm this?', 'Confirmation Dialog', function(result) {

                                            if(result){                                               

                                                jQuery.ajax(

                                                    {'type':'POST',

                                                    'data':{'place_type':parObj.attr('place_type'),'place_id':parObj.attr('place_id')},

                                                    'url':'/index.php/editcourses/removeCourse',

                                                    'cache':false,

                                                    'success':function(data){ alert(data); }

                                                    }); 

                                            }

                                        })){return }

                                         

                                        "

                            )

                    )

Hi Yugene,

Giving the below URL helped me .


'url':'index.php?r=editcourses/removeCourse',

Whatever the case if I put / before indexh.php , It is taking us to the localhost homapage

Thanks again for your help

Regards

Yii Fan

Hi,

Honestly, didn’t get the last message.

About jConfirm link - why not to use simple CHtml::link() and to write ajax request send on click on this link.

Like,


$('#link').click(function(event){

        event.preventDefault();

jConfirm and ajax request is here;

          

           });

Hi Yugene,

Thank You

about my last message … ajax request if I call the below URL


'url':'/index.php/editcourses/removeCourse'

It is not working

Removing ‘/’ before index.php resolved the issue.

I.E


'url':'index.php/editcourses/removeCourse'

worked without any issues

Yes as you said I will go to the simple link approach

Thank You again

Regards

Yii Fan