Hi,
this is my first topic and i am newbie in yii.
i have troubles using a default value in a dropdownlist.
In a form, data from 2 models are shown: student as the main model, and another model for the result of the student for a particular semester.
Semester is made of 3 fields: semester_id, year and semester_number.
I use application level default value for the semester_id.
In the form, i populate the dropdownlist this way:
<?php
$model1 = Semesters::model()->findAll();;
$data1 = array();
$data2 = array();
foreach ($model1 as $models){
$data1[$models->semester_id] = $models->semester_id . ' - ' . $models->year . ' semestre '. $models->semester_number;
}
?>
And i try to use the default value in the form (mutimodel part):
<?php $relStudentSemesterFormConfig = array(
'elements'=>array(
'student_id'=>array(
'type'=>'hidden',
'value'=>$model->student_id,
),
'semester_id'=>array(
'type'=>'dropdownlist',
'items' => $data1,
'empty'=> $data1[Yii::app()->params['defaultSemester']],
), ...
This method add a record (duplicate of my default) in the dropdownlist instead of pointing the default value.
Il i save, an error message appears ("Semester cannot be blank"), but if i choose one of the correct records, it works well.
I tried differents options like ‘default’ instead of ‘empty’, use beforeSave or beforeValidate, nothing works!
Thank you for your help.