Wednesday, January 27, 2016

How to make default value get selected in yii dropdown list

in controller

$resourceperson = ResourcePerson::model ()->findAll ();
$resourceperson = CHtml::listData ( $resourceperson, 'id', 'name' );

$this->render ( 'update', array (
'model' => $model,
'resourceperson' => $resourceperson
) );

in _form.php

<div class="row">
<?php echo $form->labelEx($model,'resource_person_id'); ?>

<?php
  //echo $form->textField($model,'resource_person_id');
/* echo $form->dropDownlist($model,'resource_person_id',$resourceperson,
array(
'id'=>'resource_person_id',
'multiple' => 'multiple',
'style'=>'width:130px;',
'prompt'=>'Please Select Resource Person'
)
); */
$selectedOptions = "";
if ($model->resource_person_id != null) {
$resourcePersons = explode(",", $model->resource_person_id);
foreach ($resourcePersons as $eachValue){
$selectedOptions[$eachValue] = array('selected'=>true);
}
}
echo $form->dropDownList($model,'resource_person_id',$resourceperson,
array(
'id'=>'resource_person_id',
'multiple' => 'multiple',
'style'=>'width:130px;',
'options' => $selectedOptions
)
);
?>

<?php echo $form->error($model,'resource_person_id'); ?>
</div>

Monday, January 18, 2016

List box with multiple selection in yii

ListBox($model,'skillid',array('id'=>'Select Skill', 'multiple' => 'multiple')); ?>

or


<div class="row">
            <?php echo $form->labelEx($model,''); ?>
            <?php
                echo '<div class="sublevel">Division:</div>';
                echo $form->dropDownList($model,'location_division', $all_divisions,//'permanent_division','', array(''=>'Please Select'), 
                array('id'=>'location_division','multiple' => 'multiple',
                    'style'=>'width:130px;',
                    'prompt'=>'Please Select'
                    ) 
                );
            ?>
            <?php echo $form->error($model,'location_division'); ?>
</div>