Yii Framework Forum: Dropdownlist - Yii Framework Forum

Jump to content

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

Dropdownlist Rate Topic: -----

#1 User is offline   ChiragChetan 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 40
  • Joined: 20-September 12
  • Location:Mumbai, India

Posted 10 January 2013 - 01:15 AM

I want to show a selected value from the table in the dropdownlist as the starting value like the "prompt" statement.
When i am displaying using prompt,then on sending the form, the value is not set and its storing blank.If i am selecting another value, then its working fine.
If i am using value instewad of prompt,its not showing selected value.Please help me.

Here $model is my model, $modellist is the list.
<?php echo $form->dropDownList($model, 'id', CHtml::listData($modellist, 'id', 'name'), array('value' =>(isset($model->name))?$model->name:"Select")); ?>
0

#2 User is offline   PeRoChAk 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 579
  • Joined: 26-November 10
  • Location:Lahore, Pakistan

Posted 10 January 2013 - 01:49 AM

can you attache screen shot of what you want to do?
Cheers
Perochak
Web Design - Logo Design - Application Development

My Blog | Forums Comparison
0

#3 User is offline   lagogz 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 478
  • Joined: 30-November 12
  • Location:Galiza

Posted 10 January 2013 - 02:38 AM

View PostPeRoChAk, on 10 January 2013 - 01:49 AM, said:

can you attache screen shot of what you want to do?


If I understand the question:

echo $form->dropDownList($model, 'IdMotivo', CHtml::listData(
                       ToMotivosIngreso::model()->findAll(), 'IdMotivo', 'Motivo'),
                       array('options'=>array(2=>array('selected'=>'selected')))); 


These codes do the item number 2 (by example, you can change it) on the list is the default item.

Regards.
-----------------------------------------------------------------------------------------------
------------------------------- VISITEN FOCUCHASART --------------------------------
-----------------------------------------------------------------------------------------------
0

#4 User is offline   Joblo 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 682
  • Joined: 12-September 10
  • Location:Austria

Posted 10 January 2013 - 02:51 AM

You don't have to set the value explicit, this should be done by Yii when the $model->id is set to a value from your listData keys.

Are you sure the $model->id is set when rendering the dropdownlist?
Check the values.


var_dump($model->attributes); //$model->id
var_dump(CHtml::listData($modellist, 'id', 'name')); 

echo $form->dropDownList($model, 'id', CHtml::listData($modellist, 'id', 'name'), array('prompt'=>'Select'));


0

#5 User is offline   ChiragChetan 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 40
  • Joined: 20-September 12
  • Location:Mumbai, India

Posted 10 January 2013 - 03:34 AM

View PostJoblo, on 10 January 2013 - 02:51 AM, said:

You don't have to set the value explicit, this should be done by Yii when the $model->id is set to a value from your listData keys.

Are you sure the $model->id is set when rendering the dropdownlist?
Check the values.


var_dump($model->attributes); //$model->id
var_dump(CHtml::listData($modellist, 'id', 'name')); 

echo $form->dropDownList($model, 'id', CHtml::listData($modellist, 'id', 'name'), array('prompt'=>'Select'));



I am getting the value, suppose a user has saved some data in a table. And later he wants to edit the data.When he is editing the data, i want to show him the previous value selected by him in the dropdownlist as the first option in place of "select".
In my code previous selected value is not shown on the list.
0

#6 User is offline   ChiragChetan 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 40
  • Joined: 20-September 12
  • Location:Mumbai, India

Posted 10 January 2013 - 03:37 AM

View PostJoblo, on 10 January 2013 - 02:51 AM, said:

You don't have to set the value explicit, this should be done by Yii when the $model->id is set to a value from your listData keys.

Are you sure the $model->id is set when rendering the dropdownlist?
Check the values.


var_dump($model->attributes); //$model->id
var_dump(CHtml::listData($modellist, 'id', 'name')); 

echo $form->dropDownList($model, 'id', CHtml::listData($modellist, 'id', 'name'), array('prompt'=>'Select'));



I am getting the value along with the id.
Suppose a user has saved some data in a table. And later he wants to edit the data.When he is editing the data, i want to show him the previous value selected by him in the dropdownlist as the first option in place of "select".
In my code previous selected value is not shown on the list.
0

#7 User is offline   AustinGeek 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 173
  • Joined: 22-September 12

Posted 17 January 2013 - 01:58 AM

The value shown in the screen should be the value stored (previously selected) in the database.
When a user returns to the screen, that value should be shown. No reason to put it on the first value in the list.
0

#8 User is offline   ChiragChetan 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 40
  • Joined: 20-September 12
  • Location:Mumbai, India

Posted 21 January 2013 - 06:04 AM

View PostAustinGeek, on 17 January 2013 - 01:58 AM, said:

The value shown in the screen should be the value stored (previously selected) in the database.
When a user returns to the screen, that value should be shown. No reason to put it on the first value in the list.

yeah you are right...but the question is how to get the previous selected value..??
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