Yii Framework Forum: selected option on dropdownlist when actionUpdate - Yii Framework Forum

Jump to content

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

selected option on dropdownlist when actionUpdate Rate Topic: -----

#1 User is offline   arsitek 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 127
  • Joined: 10-October 08

Posted 25 April 2011 - 11:22 PM

The normal way to make dropdownlist in "_form" is:
<div class="row">
        <?php $pList=project::model()->findAll('complished!=:com',array(':com'=>100)); ?>
        <?php echo $form->labelEx($model,'id_project'); ?>
        <?php echo CHtml::dropDownList('Task[id_project]','id_project', CHtml::listData($pList,'id','project_name'),
                    array('empty'=>'Select Project ')); ?>
        <?php echo $form->error($model,'id_project'); ?>
    </div>

It's ok when we need to create a new record. But on update action, We need the value was selected.
How to do that?

Thank you
0

#2 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,338
  • Joined: 12-October 09
  • Location:Croatia

Posted 26 April 2011 - 02:56 AM

The normal way would be to use
$form->dropDownList($model,'id_project',...)


This way if the attribute $model->id_project would have some value... that value would be selected...
Find more about me.... btw. Do you know your WAN IP?
1

#3 User is offline   arsitek 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 127
  • Joined: 10-October 08

Posted 26 April 2011 - 03:51 AM

View Postmdomba, on 26 April 2011 - 02:56 AM, said:

The normal way would be to use
$form->dropDownList($model,'id_project',...)


This way if the attribute $model->id_project would have some value... that value would be selected...


Thank you mdomba.. I now understand which one is the 'normal' way :D
0

#4 User is offline   Deadbody 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 18
  • Joined: 02-October 12

Posted 09 October 2012 - 03:37 PM

View PostMaurizio Domba, on 26 April 2011 - 02:56 AM, said:

The normal way would be to use
$form->dropDownList($model,'id_project',...)


This way if the attribute $model->id_project would have some value... that value would be selected...


and if I have a dependent dropdownlist like this:

 <div class="row">
             <?php echo $form->labelEx($model_estado,'uf'); ?>
             <?php
             
             echo $form->dropDownList($model_estado,'uf',$this->getEstados(),                     
                     array(  
                         'options'=>array($model_estado->id=>array('selected'=>'selected')),
                         'empty'=>'Selecione...',
                         'ajax' =>
                         array(
                             'type'=>'POST', //request type                          
                             'url'=>CController::createUrl('getCidadesDoEstado'), //action to call                           
                             'update'=>'#Endereco_cidade', // which HTML element to update                                                                                      
                             
                             )
                         )
                         
                     );
             ?>
             <?php echo $form->error($model_estado,'uf'); ?>
             
	</div>

        <div class="row">
            
                <?php echo $form->labelEx($model_endereco,'cidade'); ?>
        <?php
        echo CHtml::dropDownList(CHtml::activeName($model_endereco, 'cidade'),'',array(),  array(  
                         'empty'=>'Selecione...',
                         'id'=>'Endereco_cidade',            
                         
            
                         
                            )
                );
        ?>
        <?php echo $form->error($model_endereco,'cidade'); ?>    

            
            
	</div>     



 public function actionGetCidadesDoEstado(){
            
           
            
            $idEstado=$_POST['Estado'];
            $listaDeCidades = Cidade::model()->findAllByAttributes(array('estado'=>(int)$idEstado),array('order'=>'nome'));
             echo CHtml::tag(
                       'option', // tagname
                       array('value'=>''), // html params of tag
                       'Selecione...', // value from the item selected in the first dropdown is in the POST array
                       true // close tag
                       );
            foreach ($listaDeCidades as $cidade){
               echo CHtml::tag(
                       'option', // tagname
                       array('value'=>$cidade->id), // html params of tag
                       $cidade->nome, // value from the item selected in the first dropdown is in the POST array
                       true // close tag
                       );
               }
        }




How can i get a list of cities of the country $model_estado->id and how can I select the id of the model_cidade in a dropdown?
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