Hi,
i have a form with one dependent dropdown and a autocomplete field, both depending on a dropdown.
this is my _form.php
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'avize-form',
'enableAjaxValidation'=>false,
)); ?>
<p class="note">Campurile marcate cu <span class="required">*</span> sunt obligatorii.</p>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<?php
$models = Facturi::model()->findAll(array('order' => 'id_factura DESC'));
$list = array();
$list = CHtml::listData($models,'id_factura','SerieNumar');
$list = array('0' => 'Neasociat', '-1' => 'Urmeaza a se factura') + $list;
$model->id_cumparator = 100;
?>
<?php echo $form->labelEx($model,'id_factura'); ?>
<?php echo $form->dropDownList($model,'id_factura',$list,
array(
'ajax' => array(
'type'=>'POST', //request type
'url'=>CController::createUrl('avize/setidfactura'), // url to call.
'update'=>'#cu_factura', //selector to update
'data'=>array('Avize[id_factura]'=>'js:this.value'),
//leave out the data key to pass all form values through
))
); ?>
<?php echo $form->error($model,'id_factura'); ?>
</div>
<div class="row">
<?php
$models = Furnizori::model()->findAll(array('order' => 'nume_furnizor')); // retrieve the models from db
$list = CHtml::listData($models,'id_furnizor','nume_furnizor'); // format models as $key=>$value with listData
$id_client = 0;
?>
<?php echo $form->labelEx($model,'id_furnizor'); ?>
<?php echo $form->dropDownList($model,'id_furnizor',$list); ?>
<?php echo $form->error($model,'id_furnizor'); ?>
</div>
<div id="cu_factura">
<div class="row">
<?php echo $form->labelEx($model,'tip_cumparator'); ?>
<?php
echo $form->dropDownList($model,'tip_cumparator',$model->TipCumparator,
array(
'ajax' => array(
'type'=>'POST', //request type
'url'=>CController::createUrl('avize/settipclient'), // url to call.
'update'=>'#data', //selector to update
'data'=>array('Avize[tip_cumparator]'=>'js:this.value'),
//leave out the data key to pass all form values through
))
);
?>
<?php echo $form->error($model,'tip_cumparator'); ?>
</div>
<?php echo $form->labelEx($model,'id_cumparator'); ?>
<div class="row" id="data">
<?php
if(isset($model->tip_cumparator) && !empty($model->id_cumparator)) {
if($model->tip_cumparator == 1) {
Pj::model()->nume_pj = Pj::model()->findByPk($model->id_cumparator)->nume_pj; // Completeaza campul
$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
'name' => 'Pj[nume_pj]',
'sourceUrl' => array('pj/autocompleteTest'),
'value' => (Pj::model()->nume_pj) ? Pj::model()->nume_pj: Pj::model()->nume_pj,
'options' => array(
'showAnim' => 'fold',
'select' => 'js:function(event, ui){ jQuery("#Avize_id_cumparator").val(ui.item["id"]); }'
),
'htmlOptions' => array(
'style'=>'width: 200px;',
),
));
} elseif($model->tip_cumparator == 2) {
Pf::model()->nume_pf = Pf::model()->findByPk($model->id_cumparator)->nume_pf; // Completeaza campul
$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
'name' => 'Pf[nume_pf]',
'sourceUrl' => array('pf/autocompleteTest'),
'value' => (Pf::model()->nume_pf) ? Pf::model()->nume_pf: Pf::model()->nume_pf,
'options' => array(
'showAnim' => 'fold',
'select' => 'js:function(event, ui){ jQuery("#Avize_id_cumparator").val(ui.item["id"]); }'
),
'htmlOptions' => array(
'style'=>'width: 200px;',
),
));
};
};
?>
</div>
<?php echo $form->hiddenField($model,'id_cumparator'); ?>
<?php echo $form->error($model,'id_cumparator'); ?>
</div> <!-- EOF CU FACTURA -->
<div class="row">
<?php echo $form->labelEx($model,'serie_aviz'); ?>
<?php echo $form->dropDownList($model,'serie_aviz',Diverse::items('SerieAviz'),
array(
'ajax' => array(
'type'=>'POST', //request type
'url'=>CController::createUrl('avize/dynamicnumaraviz'), // url to call.
'success'=>'js:function(data){$("#Avize_nr_aviz").val(data);}',
'data'=>array('Avize[serie_aviz]'=>'js:this.value'),
'dataType'=>'json',
)
)); ?>
<?php echo $form->error($model,'serie_aviz'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'nr_aviz'); ?>
<?php echo $form->textField($model,'nr_aviz'); ?>
<?php echo $form->error($model,'nr_aviz'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
</div>
<?php
// pentru incarcarea automata a axajurilor
//Yii::app()->clientScript->registerScript('triggerChangeOnADropDown', '$(window).load(function(event){$("#id_cumparator").change();});');
if(!isset($model->nr_aviz)){
Yii::app()->clientScript->registerScript('triggerChangeOnADropDown', '$(window).load(function(event){$("#Avize_serie_aviz").change();});');
}
?>
<?php $this->endWidget(); ?>
</div><!-- form -->
this is from controler.php
public function actionSetIdFactura(){
$data = array();
$data["ajax_id_factura"] = $_POST['Avize']['id_factura'];
$this->renderPartial('_ajaxContent', $data, false, true);
}
and this is the _ajaxContent.php
<?php
if(isset($ajax_id_factura)){
$form=$this->beginWidget('CActiveForm', array(
'id'=>'avize-form',
'enableAjaxValidation'=>false,
));
$model =new Avize;
if($ajax_id_factura > 0){
$get_factura = Facturi::model()->findByPk((int)$ajax_id_factura);
$model->tip_cumparator = $get_factura->tip_cumparator;
$model->id_cumparator = $get_factura->id_cumparator;
?>
<div class="row">
<?php echo $form->labelEx($model,'tip_cumparator'); ?>
<?php
echo $form->dropDownList($model,'tip_cumparator',$model->TipCumparator,
array(
'ajax' => array(
'type'=>'POST', //request type
'url'=>CController::createUrl('avize/settipclient'), // url to call.
'update'=>'#data', //selector to update
'data'=>array('Avize[tip_cumparator]'=>'js:this.value'),
//leave out the data key to pass all form values through
))
);
?>
<?php echo $form->error($model,'tip_cumparator'); ?>
</div>
<?php echo $form->labelEx($model,'id_cumparator'); ?>
<div class="row" id="data">
<?php
if(isset($model->tip_cumparator) && !empty($model->id_cumparator)) {
if($model->tip_cumparator == 1) {
Pj::model()->nume_pj = Pj::model()->findByPk($model->id_cumparator)->nume_pj; // Completeaza campul
$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
'name' => 'Pj[nume_pj]',
'sourceUrl' => array('pj/autocompleteTest'),
'value' => (Pj::model()->nume_pj) ? Pj::model()->nume_pj: Pj::model()->nume_pj,
'options' => array(
'showAnim' => 'fold',
'select' => 'js:function(event, ui){ jQuery("#Avize_id_cumparator").val(ui.item["id"]); }'
),
'htmlOptions' => array(
'style'=>'width: 200px;',
),
));
} elseif($model->tip_cumparator == 2) {
Pf::model()->nume_pf = Pf::model()->findByPk($model->id_cumparator)->nume_pf; // Completeaza campul
$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
'name' => 'Pf[nume_pf]',
'sourceUrl' => array('pf/autocompleteTest'),
'value' => (Pf::model()->nume_pf) ? Pf::model()->nume_pf: Pf::model()->nume_pf,
'options' => array(
'showAnim' => 'fold',
'select' => 'js:function(event, ui){ jQuery("#Avize_id_cumparator").val(ui.item["id"]); }'
),
'htmlOptions' => array(
'style'=>'width: 200px;',
),
));
};
};
?>
</div>
<?php echo $form->hiddenField($model,'id_cumparator'); ?>
<?php echo $form->error($model,'id_cumparator'); ?>
<?php
}else{
?>
<div class="row">
<?php echo $form->labelEx($model,'tip_cumparator'); ?>
<?php
echo $form->dropDownList($model,'tip_cumparator',$model->TipCumparator,
array(
'ajax' => array(
'type'=>'POST', //request type
'url'=>CController::createUrl('avize/settipclient'), // url to call.
'update'=>'#data', //selector to update
'data'=>array('Avize[tip_cumparator]'=>'js:this.value'),
//leave out the data key to pass all form values through
))
);
?>
<?php echo $form->error($model,'tip_cumparator'); ?>
</div>
<?php echo $form->labelEx($model,'id_cumparator'); ?>
<div class="row" id="data">
<?php
if(isset($model->tip_cumparator) && !empty($model->id_cumparator)) {
if($model->tip_cumparator == 1) {
Pj::model()->nume_pj = Pj::model()->findByPk($model->id_cumparator)->nume_pj; // Completeaza campul
$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
'name' => 'Pj[nume_pj]',
'sourceUrl' => array('pj/autocompleteTest'),
'value' => (Pj::model()->nume_pj) ? Pj::model()->nume_pj: Pj::model()->nume_pj,
'options' => array(
'showAnim' => 'fold',
'select' => 'js:function(event, ui){ jQuery("#Avize_id_cumparator").val(ui.item["id"]); }'
),
'htmlOptions' => array(
'style'=>'width: 200px;',
),
));
} elseif($model->tip_cumparator == 2) {
Pf::model()->nume_pf = Pf::model()->findByPk($model->id_cumparator)->nume_pf; // Completeaza campul
$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
'name' => 'Pf[nume_pf]',
'sourceUrl' => array('pf/autocompleteTest'),
'value' => (Pf::model()->nume_pf) ? Pf::model()->nume_pf: Pf::model()->nume_pf,
'options' => array(
'showAnim' => 'fold',
'select' => 'js:function(event, ui){ jQuery("#Avize_id_cumparator").val(ui.item["id"]); }'
),
'htmlOptions' => array(
'style'=>'width: 200px;',
),
));
};
};
?>
</div>
<?php echo $form->hiddenField($model,'id_cumparator'); ?>
<?php echo $form->error($model,'id_cumparator'); ?>
<?php
}
$this->endWidget();
};
?>
in browser everithing works perfect but when i subbmit the form
$model->tip_cumparator and $model->id_cumparator is not subbmited.
how do i see all the js values ?
i also tried to renderPartial the all _form with data chosen from the first dropdown selection and now it’s form inside form.
how do i do a new refresh or how do i solve the JS values to be sent when submited ?
Thans in advance