Yii Framework Forum: Use customized dropdownlist with multimodelform - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Use customized dropdownlist with multimodelform Rate Topic: -----

#1 User is offline   ragua 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 135
  • Joined: 23-January 12
  • Location:Paris - France

Posted 24 January 2012 - 06:36 AM

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.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users