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.