unable to pre-select dropdown when update

I am having problem with my dependent dropdown, whenever I click update,

the current item that is being updated doesn’t pre-select the “city” from the dropdown based from it’s saved data from the table




	<div class="row">

		<?php echo $form->labelEx($model,'Country'); ?>

		<?php 

			  $country = new CDbCriteria; 

			  $country->order = 'CountryName ASC';

		?>

		<?php 

			  echo $form->dropDownList($model,'CountryID',CHtml::listData(Worldareascountries::model()->findAll($country),'CountryID','CountryName'),

			  			array(

			  				'ajax' => array(

			  				'type' => 'POST',

			  				'url' => CController::createUrl('wsmembersdetails/dynamicstates'),

			  				'update' => '#Wsmembersdetails_'.StateID

			  			)		

			  	  )

			  );

		?>

		<?php echo $form->error($model,'CountryID'); ?>

	</div><!--end country -->


	<div class="row">

		<?php echo $form->labelEx($model,'State'); ?>

		<?php 

			  $state = new CDbCriteria;

			  $state->order = 'StateName ASC';

		?>

		<?php 

			  echo $form->dropDownList($model,'StateID',CHtml::listData(Worldareasstates::model()->findAll($state),'StateID','StateName'),

			  			array(

			  				'ajax' => array(

			  				'type' => 'POST',

			  				'url' => CController::createUrl('wsmembersdetails/dynamiccities'),

			  				'update' => '#Wsmembersdetails_'.CityID

			  			)	

			  		)

			  );

		?>

		<?php echo $form->error($model,'StateID'); ?>

	</div><!--end state -->


	

	<div class="row">


		<?php echo $form->labelEx($model,'CityID'); ?>

		<?php echo $form->dropDownList($model,'CityID',array());?>

		<?php echo $form->error($model,'CityID'); ?>

	</div><!--end city -->



is there something I should add or remove from this code snippet ?

Your “City” dropdown does not have any data ( array() )… that’s why it cannot pre-select…

am having a hard time how to add the data in that, the model that holds and save that data from that form has this rule




	public function relations()

	{

		// NOTE: you may need to adjust the relation name and the related

		// class name for the relations automatically generated below.

		return array(

			'member' => array(self::BELONGS_TO, 'Wsmembers','MemberShipID'),

			'staff' => array(self::HAS_MANY, 'Wsmembersstaff','CompanyID'),

			'stateID' => array(self::BELONGS_TO, 'Worldareasstates','StateID'),

			'cityID' => array(self::BELONGS_TO, 'Worldareascities', 'CityID'),

			'countryID' => array(self::BELONGS_TO, 'Worldareascountries', 'CountryID'),

		);

	}



it saves the country id, state id, city id in the current table/model

how am I gonna code/select the data from the row and present it as text

like key/value pair ? :mellow:

I don’t understand your problem… you already have all you need as the insert works…

you only need on actionUpdate to populate the city dropdown…