Howto Close JqueryUi Dialog

I use the extension quickdlgs.

I need to close a dialog after I click on a button on the dialog. This button calls an action that redirects to another view. That should not be rendered inside the dialog. I want to hide the dialog before the redirect is executed.

I tried to register a JQuery Script. But I do not know how to hide the dialog. :blink:


Yii::app()->clientScript->registerScript('closeDialog',"

    $('#yt2').click(function() {

       <img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />??

    });",CClientScript::POS_READY);

Please give me a hint.

Here are two extracts from some code of mine.

The first simply calls the dialog’s close method.

The second also removes the dialog from the DOM.


$jsclosedialog=<<<EOJS

    	jQuery('#$_dialogId').dialog('close');

EOJS;

$_but = array(

        Yii::t('app','Cancel')=>'js:function(){jQuery(this).dialog(\'close\').parent().remove();jQuery(this).remove();}',

);

Have you tried to use jui method for it?

http://api.jqueryui.com/dialog/#method-close

Using


$('#yt2')

[size="2"]is not recommended as this may change over time depending on the elements that you put on your page.[/size]

[size="2"]You have two options:[/size]

[list=1][]Get the id from the widget (->getId() ).[]Provide your own id (as a parameter to the widget).[/list]

Now I registered the following JavaScript on the view:


Yii::app()->clientScript->registerScript('closeDialog',"

    $('#convertButton').click(function() {

        window.parent.jQuery('#noten-grid_c9updateWdgt-dlg').dialog('close');

    });",CClientScript::POS_READY);

The above code lets the dialog close, because I found the id of the dialog.

A "not so clean" solution is to destroy your dialog after a slight timeout with window.setTimeout .

Hi

Here is my improved code.

I use ‘$jsClsoeDialog’, if I want to close/destroy the dialog explicitally in javascripnt.

The code ‘$jsCloseScript’, attaches this destroy code to the ‘dialogclose’ event.

Basically, the code below, combined with NLSClientScript, allows me to load CJuiDialogs through ajax. In the ‘ajax’ success function, I will call ‘$jsCloseDialog’ code prior to doing “jQuery(‘body’).append(html)”, The view has to be partially rendered in the controller.


            $jsCloseDialog=<<<EOJS

	try{jQuery('#$id').dialog('destroy').detach();}catch(e){}

EOJS;


            $jsCloseScript=<<<EOJS

	jQuery('#$id').bind('dialogclose',function(){ $jsCloseDialog});

EOJS;

            $this->beginWidget('zii.widgets.jui.CJuiDialog', array(

                    'id'=>$id,

                    'options'=>array(

                            'dialogClass'=>$this->class,

                            'show' => 'blind',

                            'hide' => 'explode',

                            'modal' => true,

                            'title' => $title,

                            'autoOpen'=>true,

                    ),

            ));

            echo CHtml::tag('span',array(),$content);

            Yii::app()->clientScript->registerScript(__FILE__."#".$id,$jsCloseScript);

            $this->endWidget('zii.widgets.jui.CJuiDialog');