Quantcast
Channel: Yii Framework Forum
Viewing all articles
Browse latest Browse all 18717

DropDownLists dependientes mantener valores

$
0
0
Hola a todos...

Tengo dos dropdownlist dependientes definidos de la siguiente forma

<tr>
	<td style="padding: 4px 10px 4px 0px; width: 130px;"><?php echo $form->labelEx($model,'unit_owner'); ?></td>
		<td style="width: 240px;">
			<?php echo $form->dropDownList($model,'unit_owner', CHtml::listData(Unit::model()->findAll(array('order' => 'name ASC')), 'id', 'name'), 				   
									array(
								            	'ajax' => array(
								                'type'=>'POST',
								                'url'=>CController::createUrl('Promotion/dynamicServiceOwner'),
								                'update'=>'#'.CHtml::activeId($model,'service_owner'
									)
							),'prompt' => ''
						)); ?>
		</td>
	<td style="width: 120px;"><?php echo $form->labelEx($model,'service_owner'); ?></td>
	<td><?php echo $form->dropDownList($model,'service_owner',array(), array('style' => 'width:150px')); ?></td>
</tr>


El codigo del controller es el siguiente:

	public function actionDynamicServiceOwner()
	{
		$unit_owner = $_POST['Promotion']['unit_owner'];

	    $data=ServiceOwner::model()->findAll(array('order'=>'name', 'condition'=>'unit=:unit', 'params'=>array(':unit'=>(int) $unit_owner)));
	
	    $data=CHtml::listData($data,'id','name');
	    foreach($data as $value=>$name)
	    {
	        echo CHtml::tag('option',
	                   array('value'=>$value),CHtml::encode($name),true);
	    }
	}


Todo funciona bien hasta el momento en que envio el formulario a procesar y por cualquier error de validacion se vuelve a renderizar la vista. En ese momento el valor del segundo dropdownlist se pierde. Alguien me puede echar una mano.

Gracias por adelantado.

att.

Viewing all articles
Browse latest Browse all 18717

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>