Hi @all, I’m so newbie…
Some months of very sparse yii developing (maybe a 30 hours session of learning + coding) and I have almost finished a little application based on few tables.
No problem on models and controllers, very quick and smart coding and learning, but I’m a little bit stuck on view management.
(yii 1.1.8 and firefox and eclipse internal browsers)
I have a form with a CGridView, 2 JuiDialog nested, and I’m have some trouble on refreshing the CGridView on the original form when I close the first JuiDialog when 2nd JuiDialog it’s present.
If I comment out the second JuiDialog (used for selecting a referred data) in the first JuiDialog (an "Add new…" facility), the $.fn.yiiGridView.update works fine.
So, this is code snippet (quite long, but complicated situation… ) :
file _form.php
...
$VoceanalisiDataProvider=new CArrayDataProvider($model->voceanalisis);
$this->widget('zii.widgets.grid.CGridView',
array('id'=>'voceanalisis-grid',
'dataProvider'=>$VoceanalisiDataProvider,
'columns'=>array( ... )));
echo CHtml::ajaxButton(
Yii::t('voceanalisi','Add Voceanalisi'),
$this->createUrl('voceanalisi/addnew',array('analisi'=>$model->id)), //obiouvsly, addnew added in controller
array(
'onclick'=>'$("#voceanalisiDialog").dialog("open"); return false;',
'update'=>'#voceanalisiDialog'),
array('id'=>'showVocenalisiDialog'));
...
file createDialog.php
...
$this->beginWidget('zii.widgets.jui.CJuiDialog',array(
'id'=>'voceanalisiDialog',
'options'=>array(
'title'=>Yii::t('voceanalisi','Create VoceAnalisi'),
...)));
echo $this->renderPartial('_formDialog', array('model'=>$model,'analisi'=>$analisi));
...
file _formDialog.php (with the incriminated JuiDialog)
...
<?php $this->beginWidget('zii.widgets.jui.CJuiDialog',
array( 'id'=>'voce_dialog',
// additional javascript options for the dialog plugin
'options'=>...
));
$vocedataProvider=new CActiveDataProvider('voce');
$this->widget('zii.widgets.grid.CGridView',
array( 'id'=>'voce-grid',
'dataProvider'=>$vocedataProvider,
'filter'=>Voce::model(),
'columns'=>array( /* columns and some js to fill the right textField*/));
$this->endWidget('zii.widgets.jui.CJuiDialog');
echo CHtml::ImageButton('images/view.png',
array('onclick'=>'$("#voce_dialog").dialog("open"); return false;',
)) ?>
....
//there where I call yiiGridView update, thats work if I had not the voce_dialog JuiDialog on code:
echo CHtml::ajaxSubmitButton(Yii::t('voceanalisi','Create VoceAnalisi'),CHtml::normalizeUrl(array('voceanalisi/addnew','render'=>false)),array('success'=>'js: function(data) {
$("#voceanalisiDialog").dialog("close");
$.fn.yiiGridView.update("voceanalisis-grid");
}'),array('id'=>'closeVoceanalisiDialog'));
...
VoceAnalisi.php
public function actionAddnew($analisi=NULL) {
$model=new VoceAnalisi;
$this->performAjaxValidation($model);
$flag=true;
if(isset($_POST['VoceAnalisi']))
{ //add record
$flag=false;
$model->attributes=$_POST['VoceAnalisi'];
$model->save();
}
if($flag) { //render
Yii::app()->clientScript->scriptMap['jquery.js'] = false;
$this->renderPartial('createDialog',array('model'=>$model,'analisi'=>$analisi),false,true);
}
}
It’s all right that i have ajax validation as true and all endwidgets and other stuffs allright.
Some ideas?
This piece of code if inherited from someone’s example in tutorials or this forum (I don’t remember, it’s agoust work).
I must replicate the "*Dialog.php" file structure?
For me isn’t so clear why it must be done also the first time…
Sorry for my yii ignorance - and not so beatuiful english - , but… it’s very cool…
Another question (maybe related with issue…):
why the addnew function it’s armed from each ajax event also on voce_dialog JuiDialog events that’s related on another model (Voce instead of VoceAnalisi) (cacthed with eclipse debugging) ?
Thank you so much,
Emanuele