Nested JUIDialogs using AjaxLink

Hello,

1st, let me start off by saying, wow…I have been so impressed by yii since I found it! I’m totally loving it.

I’m not sure where to start. I will try to explain what’s going on here.

By the way, my problem is closing a dialog. I know, sounds simple right, yes, I know the code for it, and yes it’s running. Problem is, is that it’s not closing the dialog.

I’m pretty sure it has something to do with loading multiple ajax requests [by the way, I have done a lot of research on this was well, and have already resolved some of the problem by preventing jquery.js from being loaded multiple times by using clientScriptMap disable jquery.js and this solved some of my problems]. I also already read up on the uniqueID issue and have taken care of that by assigning the ajaxID [in the GET, the ‘_’ variable [underscore, not a text face :)]] to the end of the id in the htmloptions so it reads, closeBusinessEntityDialog123456798 [being the ajax number unique to each request]

I have the following models:

feinfo

businessentity

locationinfo

feinfo has a parent, business entity. BusinessEntity has a parent location info.

What I’m trying to do is bring up the create form for feinfo, click a button, create new business entity, have that open a modal dialog with the create businessentity form in it. And on that form, have another link, create Location Info. Clicking that link would open another modal dialog, this time containing the create form for the location info record.

All of that being said, before I go any further, I would like to point out that all of my functionality is working, creating the record using ajax/controller-response, passing the ID back to the parent form using jquery.

My only problem is that the line that is supposed to close the dialog:


#(myDialog).dialog("close");

is not working. The dialog stays open.

I started out by implementing the cookbook found here on my _form.php for my feinfo model:

http://www.yiiframework.com/doc/cookbook/72/

This was the exact functionality I needed for my web application, and it worked.

The next thing I did was extend this functionality by nesting another ajaxlink/juidialog [using the same method as in the cookbook] inside my current juidialog. I did this by opening the _formDialog.php file I had created while going through the cookbook, and put the needed ajax link, and new div tag for the placeholder for the juidialog.

This worked perfectly.

I could open my regular form [with the 1st ajax link in it], click the ajax link and get a dialog. Inside that dialog there was another ajax link to create another dialog to a different table.

However, it will not close the form [.dialog("close");] even though the code is there and i can see the javascript gets exectued properly

This is really strange because my 1st dialog [Business Entity Dialog], never has a problem closing. It always closes, and what doesn’t make since is why the other nested dialogs sometimes don’t close and sometimes do.

For example,

Open Form for Create New FEInfo

Click link, Create new Business Entity [dialog pops up]

Click link, Create new Location Information [dialog pops up]

fill out locationinfo form, save [closes propery]

fill out businessentity form, save [closes properly]

remaining on the New FEInfo page

Click link, Create new Business Entity [dialog pops up]

Click link, Create new Location Information [dialog pops up]

fill out locationinfo form, save [will NOT close propery] but the ID ends up in feinfo like it should.

Here is where I just manually click the ‘x’ to close the dialog, which works fine.

My only problem is I don’t want to have to manually close the form.

I have tried the uniqueID ajaxlink fix, which resolved most of my issues. I am not loading the jquery.js multipule times [disabled in clientscript map]

I’m about to lose my marbles over this =/ for something so simple I though I would have figured this out by now.

Thanks so much for your help

Could be something simple like a mispelled word or even something in jQuery…

It’s difficult to say what can be wrong here… without debugging the code (FireBug?)…

Is really difficoult to help you in this situation.

You did such a big and complex interface that is difficoult to immagine what is going on.

The only advice I can give you, is how I solved a case that was, maybe, similar.

I don’t use the id for close the dialog, pass the div among all js function. So when you are open the form, you are doing something like:




$(#Offer_departmentID).dialog('open');



I do:




div= $(#Offer_departmentID);

div.dialog('open');



As, probably, you will do an ajax request immediatly, in this ajax request I do:




function createNew(ac, div)

{

	$.ajax({

		type: 'POST',

		url: '<?php echo CHtml::normalizeUrl(array('conto/create'))?>',

		data: $('#'+div.attr('id')+' form').serialize(),

		success: function (response){

			data=JSON.parse(response);

			if (data.status=='form')

			{

				div.html(data.data);

				div.find('form').submit(function(){createNew(ac, div); return false;});

			}

			else

				div.dialog("close");

			

		}

	});

	

}



So the div is passed "hand by hand" among all ajax request. That allows not to care about ID (because there is always some problem).

This is pure js code, I didn’t used Yii wrapper for work more fast. I had some ideas of redo in a more Yii style, but when the code is working, the will to change it disappear…

I hope my idea helps you.

The error is only the second time, if it mispelled, how can work the first? There is something of more tasty behind this problem…

Thanks the feedback!

zaccaria, I will try your idea and let you know how it works, thanks for the suggestion.

Here’s some of the code giong on here:

1st of all, the process is:

1 - start @ FEInfo _form.php - ie. create new FEInfo regular form

2 - on it, click the create business entity ajax link

3 - this sends a request to the business entity controller and passes, ‘addNew’

4 - the controller responds and calls partialRender(’_formDialog’) to create the widget and html content for the juidialog

5 - in the _formDialog, it creates the juidialog widget and for it’s content, calls _renderPartial(_formDialog) to

generate the html to the form to be used as contents of the juidialog. note in _formDialog I have tried with fase true and without either, both have weird results.

Hopefully that explains a little bit as to what’s going on.

PS. Code is very sloppy, going at breakneck speeds here…will try to clean up once I get it figured out

_form.php




<div class="form">




<?php


	//Note: use findall() so it will auto populate a dropdown.

	//pull in the business entity record associated with the project


	if (!$model->isNewRecord)

	{

		$businessEntityModel = Businessentity::model()->findAll('id = '.$model->businessentity->id);			

	}

	else

	{

		$businessEntityModel = array();

	}


	$businessEntityList = CHtml::listData($businessEntityModel, 

                'id', 'name');

	

	$FEInspDistEntityModel = Feinspdist::model()->findAll();

	$FEInspDistEntityList = CHtml::listData($FEInspDistEntityModel, 

                'id', 'name');

	

                

?>


<?php $form=$this->beginWidget('CActiveForm', array(

	'id'=>'fe-info-form',

	'enableAjaxValidation'=>true,

)); ?>


	<p class="note">Fields with <span class="required">*</span> are required.</p>

		

	<?php echo $form->errorSummary($model); ?>


	<div class="row">

		<?php echo $form->labelEx($model,'name'); ?>

		<?php echo $form->textField($model,'name',array('size'=>60,'maxlength'=>80)); ?>

		<?php echo $form->error($model,'name'); ?>

	</div>


	<div class="row">

		<?php echo $form->labelEx($model,'BUSINESSENTITY_ID'); ?>

		<!--<?php echo $form->textField($model,'BUSINESSENTITY_ID'); ?>-->

		<?php echo $form->dropDownList($model, 'BUSINESSENTITY_ID', 

              $businessEntityList,

              array('empty' => '(Select Create New)')); ?>

		<?php echo $form->error($model,'BUSINESSENTITY_ID'); ?>

	</div>


	<div class="row">

		

		<div id="job">		    		    

		    <?php

		    

		    echo CHtml::ajaxLink(

		    	"Create Business Entity",

		    	Yii::app()->createUrl( 'businessentity/AddNew' ),

		    	//ajax options

			    array(			    	

			        'onclick'=>'$("#businessEntityDialog").dialog("open"); return false;',

			        'update'=>'#businessEntityDialog'

			    	),

			    //htmloptions

			    array('id'=>'showBusinessEntityDialog',

			    	'href'=> Yii::app()->createUrl('businessentity/AddNew'),

			    	)

			    );

		        ?>

		    <div id="businessEntityDialog"></div>

		</div>		

	</div>


	<div class="row">

		<?php echo $form->labelEx($model,'ETYPE'); ?>

		<?php echo $form->textField($model,'ETYPE',array('size'=>60,'maxlength'=>80)); ?>

		<?php echo $form->error($model,'ETYPE'); ?>

	</div>


	<div class="row">

		<?php echo $form->labelEx($model,'INSPDISTRICT'); ?>

		<!--<?php echo $form->textField($model,'INSPDISTRICT',array('size'=>2,'maxlength'=>2)); ?>-->

		<?php echo $form->dropDownList($model, 'INSPDISTRICT', 

              $FEInspDistEntityList,

              array('empty' => '(Select a District)')); ?>

		<?php echo $form->error($model,'INSPDISTRICT'); ?>

	</div>


	<div class="row">

		<?php echo $form->labelEx($model,'NUMFOODHANDLER'); ?>

		<?php echo $form->textField($model,'NUMFOODHANDLER',array('size'=>10,'maxlength'=>10)); ?>

		<?php echo $form->error($model,'NUMFOODHANDLER'); ?>

	</div>


	<div class="row">

		<?php echo $form->labelEx($model,'NUMFOODSVCOP'); ?>

		<?php echo $form->textField($model,'NUMFOODSVCOP',array('size'=>10,'maxlength'=>10)); ?>

		<?php echo $form->error($model,'NUMFOODSVCOP'); ?>

	</div>


	<div class="row">

		<?php echo $form->labelEx($model,'NUMOTHEREMP'); ?>

		<?php echo $form->textField($model,'NUMOTHEREMP',array('size'=>10,'maxlength'=>10)); ?>

		<?php echo $form->error($model,'NUMOTHEREMP'); ?>

	</div>


	<div class="row">

		<?php echo $form->labelEx($model,'NUMTOTALEMP'); ?>

		<?php echo $form->textField($model,'NUMTOTALEMP',array('size'=>10,'maxlength'=>10)); ?>

		<?php echo $form->error($model,'NUMTOTALEMP'); ?>

	</div>


	<div class="row">

		<?php echo $form->labelEx($model,'MGRREQUIRED'); ?>

		<?php echo $form->textField($model,'MGRREQUIRED',array('size'=>1,'maxlength'=>1)); ?>

		<?php echo $form->error($model,'MGRREQUIRED'); ?>

	</div>


	<div class="row">

		<?php echo $form->labelEx($model,'RESTRICTION'); ?>

		<?php echo $form->textField($model,'RESTRICTION',array('size'=>30,'maxlength'=>30)); ?>

		<?php echo $form->error($model,'RESTRICTION'); ?>

	</div>


	<div class="row">

		<?php echo $form->labelEx($model,'SMKRISK'); ?>

		<?php echo $form->textField($model,'SMKRISK',array('size'=>10,'maxlength'=>10)); ?>

		<?php echo $form->error($model,'SMKRISK'); ?>

	</div>


	<div class="row">

		<?php echo $form->labelEx($model,'RISKPRIORITY'); ?>

		<?php echo $form->textField($model,'RISKPRIORITY',array('size'=>10,'maxlength'=>10)); ?>

		<?php echo $form->error($model,'RISKPRIORITY'); ?>

	</div>


	<div class="row">

		<?php echo $form->labelEx($model,'GREASETRAPSITE'); ?>

		<?php echo $form->textField($model,'GREASETRAPSITE',array('size'=>32,'maxlength'=>32)); ?>

		<?php echo $form->error($model,'GREASETRAPSITE'); ?>

	</div>


	<div class="row">

		<?php echo $form->labelEx($model,'BEERWINE'); ?>

		<?php echo $form->textField($model,'BEERWINE',array('size'=>1,'maxlength'=>1)); ?>

		<?php echo $form->error($model,'BEERWINE'); ?>

	</div>


	<div class="row">

		<?php echo $form->labelEx($model,'CITYFOODLICENSENUM'); ?>

		<?php echo $form->textField($model,'CITYFOODLICENSENUM',array('size'=>16,'maxlength'=>16)); ?>

		<?php echo $form->error($model,'CITYFOODLICENSENUM'); ?>

	</div>


	<div class="row">

		<?php echo $form->labelEx($model,'MTMKTLICENSENUM'); ?>

		<?php echo $form->textField($model,'MTMKTLICENSENUM',array('size'=>16,'maxlength'=>16)); ?>

		<?php echo $form->error($model,'MTMKTLICENSENUM'); ?>

	</div>


	<div class="row">

		<?php echo $form->labelEx($model,'DTACTIVE'); ?>

		<?php echo $form->textField($model,'DTACTIVE'); ?>

		<?php echo $form->error($model,'DTACTIVE'); ?>

	</div>


	<div class="row">

		<?php echo $form->labelEx($model,'DTEXPIRATION'); ?>

		<?php echo $form->textField($model,'DTEXPIRATION'); ?>

		<?php echo $form->error($model,'DTEXPIRATION'); ?>

	</div>


	<div class="row">

		<?php echo $form->labelEx($model,'TEMP'); ?>

		<?php echo $form->textField($model,'TEMP',array('size'=>1,'maxlength'=>1)); ?>

		<?php echo $form->error($model,'TEMP'); ?>

	</div>


	<div class="row">

		<?php echo $form->labelEx($model,'DAYSHOURSOPERATION'); ?>

		<?php echo $form->textField($model,'DAYSHOURSOPERATION',array('size'=>60,'maxlength'=>250)); ?>

		<?php echo $form->error($model,'DAYSHOURSOPERATION'); ?>

	</div>


	<div class="row">

		<?php echo $form->labelEx($model,'PHOTO'); ?>

		<?php echo $form->textField($model,'PHOTO'); ?>

		<?php echo $form->error($model,'PHOTO'); ?>

	</div>


	<div class="row">

		<?php echo $form->labelEx($model,'PHOTOTYPE'); ?>

		<?php echo $form->textField($model,'PHOTOTYPE',array('size'=>20,'maxlength'=>20)); ?>

		<?php echo $form->error($model,'PHOTOTYPE'); ?>

	</div>


	<div class="row buttons">

		<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>

	</div>


<?php $this->endWidget(); ?>


</div><!-- form -->



BusinessEntityController.actionAddNew




public function actionAddnew()

{	

	$this->layout = false;

	

	Yii::app()->clientscript->scriptMap['jquery.js'] = false;

		

        $model=new BusinessEntity;

        

        // Ajax Validation enabled

        $this->performAjaxValidation($model);

        

        // Flag to know if we will render the form or try to add new BusinessEntity

        $flag=true;

        

        if(isset($_POST['BusinessEntity']))

        {

            $flag=false;

            $model->attributes=$_POST['BusinessEntity'];

 

            if($model->save()) {

            	

                //Return an <option> and select it

				echo CHtml::tag('option',array (

	                                'value'=>(int)$model->id,

	                                'selected'=>true

	                            	),

                            	CHtml::encode($model->name),true);

	    }

	}

        

	if($flag) {

            $this->renderPartial('createDialog',array('model'=>$model,'number'=>$_GET['_'],),false,true);

        }

}



BusinessEntity - _createDialog.php




<?php 

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

                'id'=>'businessEntityDialog',

                'options'=>array(

                    'title'=>Yii::t('businessentity','Create Business Entity'),

                    'autoOpen'=>true,

                    'modal'=>'true',

                    'width'=>'auto',

                    'height'=>'auto',

                ),

                ));

echo $this->renderPartial('_formDialog', array('model'=>$model, 'number'=>$number)); ?>

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



BusinessEntity - _formDialog.php




<div class="form" id="businessEntityDialog">

 

<?php


	//Note: use findall() so it will auto populate a dropdown.

	//pull in the business entity record associated with the project


	if (!$model->isNewRecord)

	{

		$locationInfoModel = LocationInfo::model()->findAll('id = '.$model->locationinfo->id);

		$ownerInfoModel = OwnerInfo::model()->findAll('id = '.$model->ownerinfo->id);			

	}

	else

	{

		$locationInfoModel = array();

		$ownerInfoModel = array();

	}


	$locationInfoList = CHtml::listData($locationInfoModel, 

                'id', 'name');

	

	$ownerInfoList = CHtml::listData($ownerInfoModel, 

                'id', 'name');

                

?>

 

<?php $form=$this->beginWidget('CActiveForm', array(

    'id'=>'business-entity-form',

    'enableAjaxValidation'=>true,

)); 

//I have enableAjaxValidation set to true so i can validate on the fly the

?>

 

    <p class="note">Fields with <span class="required">*</span> are required.</p>

 

    <?php echo $form->errorSummary($model); ?>


    <div class="row">

		<?php echo $form->labelEx($model,'name'); ?>

		<?php echo $form->textField($model,'name',array('size'=>60,'maxlength'=>80)); ?>

		<?php echo $form->error($model,'name'); ?>

	</div>


	<div class="row">

		<?php echo $form->labelEx($model,'create_date'); ?>

		<?php echo $form->textField($model,'create_date'); ?>

		<?php echo $form->error($model,'create_date'); ?>

	</div>


	<div class="row">

		<?php echo $form->labelEx($model,'last_update'); ?>

		<?php echo $form->textField($model,'last_update'); ?>

		<?php echo $form->error($model,'last_update'); ?>

	</div>


	<div class="row">

		<?php echo $form->labelEx($model,'created_by'); ?>

		<?php echo $form->textField($model,'created_by'); ?>

		<?php echo $form->error($model,'created_by'); ?>

	</div>


	<div class="row">

		<?php echo $form->labelEx($model,'last_updated_by'); ?>

		<?php echo $form->textField($model,'last_updated_by'); ?>

		<?php echo $form->error($model,'last_updated_by'); ?>

	</div>


	<div class="row">

		<?php echo $form->labelEx($model,'deleted_by'); ?>

		<?php echo $form->textField($model,'deleted_by'); ?>

		<?php echo $form->error($model,'deleted_by'); ?>

	</div>

 

	<div class="row">

		<?php echo $form->labelEx($model,'STRUCTUREINFO_ID'); ?>

		<!--<?php echo $form->textField($model,'STRUCTUREINFO_ID'); ?>-->

		<?php echo $form->dropDownList($model, 'STRUCTUREINFO_ID', 

              $locationInfoList,

              array('empty' => '(Select Create New)')); ?>

		<?php echo $form->error($model,'STRUCTUREINFO_ID'); ?>

	</div>

	

	<div class="row">

		

		<div id="location">		    		    

		    <?php

		    

		    echo CHtml::ajaxLink(

		    	"Create Location",

		    	Yii::app()->createUrl( 'locationinfo/AddNew' ),

		    	//ajax options

			    array(			    	

			        'onclick'=>'$("#locationInfoDialog".dialog("open"); return false;',

			        'update'=>'#locationInfoDialog'

			    	),

			    //htmloptions

			    array('id'=>'showLocationInfoDialog'.$number,

			    	'href'=> Yii::app()->createUrl('locationinfo/AddNew'),

			    	)

			    );

		        ?>

		    <div id="locationInfoDialog"></div>

		</div>		

	</div>


	<div class="row">

		<?php echo $form->labelEx($model,'OWNERINFO_ID'); ?>

		<!--<?php echo $form->textField($model,'OWNERINFO_ID'); ?>-->

		<?php echo $form->dropDownList($model, 'OWNERINFO_ID', 

              $ownerInfoList,

              array('empty' => '(Select Create New)')); ?>

		<?php echo $form->error($model,'OWNERINFO_ID'); ?>

	</div>

	

	<div class="row">

		

		<div id="owner">		    		    

		    <?php

		    

		    echo CHtml::ajaxLink(

		    	"Create Owner",

		    	Yii::app()->createUrl( 'ownerinfo/AddNew' ),

		    	//ajax options

			    array(			    	

			        'onclick'=>'$("#ownerInfoDialog".dialog("open"); return false;',

			        'update'=>'#ownerInfoDialog'

			    	),

			    //htmloptions

			    array('id'=>'showOwnerInfoDialog'.$number,

			    	'href'=> Yii::app()->createUrl('ownerinfo/AddNew'),

			    	)

			    );

		        ?>

		    <div id="ownerInfoDialog"></div>

		</div>		

	</div>


	<div class="row">

		<?php echo $form->labelEx($model,'ENUM'); ?>

		<?php echo $form->textField($model,'ENUM'); ?>

		<?php echo $form->error($model,'ENUM'); ?>

	</div>


	<div class="row">

		<?php echo $form->labelEx($model,'STATUS'); ?>

		<?php echo $form->textField($model,'STATUS',array('size'=>1,'maxlength'=>1)); ?>

		<?php echo $form->error($model,'STATUS'); ?>

	</div>


	<div class="row">

		<?php echo $form->labelEx($model,'DTACTIVE'); ?>

		<?php echo $form->textField($model,'DTACTIVE'); ?>

		<?php echo $form->error($model,'DTACTIVE'); ?>

	</div>


	<div class="row">

		<?php echo $form->labelEx($model,'GMNAME'); ?>

		<?php echo $form->textField($model,'GMNAME',array('size'=>32,'maxlength'=>32)); ?>

		<?php echo $form->error($model,'GMNAME'); ?>

	</div>


	<div class="row">

		<?php echo $form->labelEx($model,'GMEMAIL'); ?>

		<?php echo $form->textField($model,'GMEMAIL',array('size'=>60,'maxlength'=>80)); ?>

		<?php echo $form->error($model,'GMEMAIL'); ?>

	</div>


	<div class="row">

		<?php echo $form->labelEx($model,'GMPHONE'); ?>

		<?php echo $form->textField($model,'GMPHONE',array('size'=>60,'maxlength'=>80)); ?>

		<?php echo $form->error($model,'GMPHONE'); ?>

	</div>

 

    <div class="row buttons">

        <?php echo CHtml::ajaxSubmitButton(Yii::t('businessentity','Create Business Entity'),CHtml::normalizeUrl(array('businessentity/addnew','render'=>false)),array('success'=>'js: function(data) {                       

        				$("#FeInfo_BUSINESSENTITY_ID").append(data);                        

                        $("#businessEntityDialog").dialog("close");

                    }'),array('id'=>'closeBusinessEntityDialog'.$number)); ?>

    </div>

 

<?php $this->endWidget(); ?>

 

</div>



As you can see, the _formDialog.php has another ajax link to both owner and location information.

So, from each dialog, you can create a new record of that type, and return it’s id.

One additional complication, in some cases, ie. this is a requirement, the user must be able to "create" [ie. click create business entity], a business entity, and before they submit the form, be able to open another dialog form from inside the business entity dialog form in order to create one of the business entity related records. I hope this makes sense.

By the way, zaccaria, how would you recommend I replace the existing CHtml::AjaxLink’s with your javascript code. I know the solution is to get a way from CClientScript, from what I’ve read about your ajax experiences, by putting the javascript into the form that’s rendered.

I have tried that by in my _createDialog.php, before the widget call, at the top, I would try calling registerClientFile(…) but the dialog wouldn’t open.

Also, I tried using your Zcontroller, but I couldn’t get very far in using because I ran into an odd problem. The html would come back, but there wouldn’t be a ‘style’ almost for the dialog. ie. it rendered just the links and html, but no tags, so the dialog wasn’t being drawn properly. Very odd.

Thanks again for the input,

ps. I can send links of firebug data, but I’m not seeing anything other than ajax validation responces, the addNew requests to the controllers, and a request each time I open a new dialog, for jquery-ui.min.js and jquery.yiiactiveform.js.

I even see the createNew action sent on ‘create new business entity’ button click from the JuiDialog at it’s correct time.

Only issue seems to be in getting jquery to resolve the name of my dialogs and then run the .close() command against it.

My advice is to write all code directly in the view, without using ClientScript.

Just some more questions: what about if the user insert uncorrect data?

You will close the dialog anyway.

My idea is to put a simple submit button in the form instead of the ajaxSubmit, and then give at the onSubmit of the form the function you see.

The action does somethng like:




	public function actionCreate()

	{

		$model=new conto;

		if(isset($_POST['conto']))

		{

			$model->attributes=$_POST['conto'];

			if($model->save())					

			{

				echo CJSON::encode(

					array('status'=>'success', 

						'data'=>array('id'=>$model->primaryKey, 'label'=>$model->recordDescription),));

				exit;

			}

			

		}

			echo CJSON::encode(array('status'=>'form', 'data'=>$this->renderPartial('_form',array('model'=>$model, 'update'=>false), true)));

	}




So, if validation is successfully, it returns a status success (and I am checking it in the javascript you saw).

If validation fails, I return the form (with fields in red), so you can show the user his errors.

I appreciate very much that you tried my ZController, but this is a problem too specific even for this. :)

I mean, we should realize that all this wrapper (CJuiWidget, CHtml::ajax and so on) are just wrapper, they can help us in write less code and, in lot of occasion, help us forgetting of what’s going on in javascript because they are working good in many standard situations.

The problem we are facing is not standard at all, the framework has no object for this (because, even it Yii gives a lot of nice js wrapper, is a PHP (serverside) framework) and is not fair to ask Yii to do our job in javascript.

So, in this situations, I advice (and I am the first doing like that) to resolve the question among you and javascript, without any helps of Yii. My aim proposing ZController was to extend a bit more (a lot more) this area of standard situation in wich wrapper helps, but this situation is out of bound even for this.

Just start with an healthy




<script type="text/javascript">



And all stuff will become immediatly very easy.

Thank you so much!!

Your ideas really helped a lot.

I finally got everything worked out. Finally, no more odd behavior.

There were quite a number of things required in order to make all of this work properly.

  1. include javascript files for yii active form, and jquery.ui, at the top of the feinfo/_form.php file - it is from this page that all dialogs will be opened from, so javascript needs to be included

  2. do not allow any of the ajax responses to send down javascript files [sending these files down causes the init() functions to be re-ran again and cause really odd behavior.

  3. programmed the event-handlers [javascript code] manually into script tags and placed that that the top of the view being rendered via ajax [thanks Zach!]

  4. finally, what seemed to do the most for me, was not writing the div placeholder into the view page, but instead, onClick [open dialog], have it create the div tag for the dialog, and have jquery ajax get the content and have that content loaded into the dialog. Once the dialog is prepared, insert the div you created into the document at the end of the body tag.

This accomplishes two things, 1 - makes the div tag, creates the dialog, loads the content, and opens the dialog in sequence using function chains from jquery. 2 - this prevents multiple copies of the div that holds the dialog from possibly being created [ie. manually controls the div tag process]

  1. On exiting the dialog, weather from ‘ESC’ or clicking the ‘x’ or properly saving the form, close the form and REMOVE the div tag from the html document completely. This allows the ‘create the div tag’ process mentioned earlier to work

It seems that #4 and #5 where the ones I had to add on top of my original post.

I can’t believe I got this working, by far one of the most complicated UI’s for a webapp…stupid database design ;)