mini998
(Ima Silva)
December 10, 2013, 11:30am
1
I have below code
echo CHtml::dropDownList('one', ((isset($data1)) ? $data1 : ""),CHtml::listData(Property::model()->findAll($criteria), 'id', 'name'), array(
'prompt' => ((isset($name1)) ? $name1 : "Empty"),
'id' => 'one',
'ajax' => array(
'type' => 'POST', //request type
'url' => CController::createUrl('dynamicList'), //url to call.
//Style: CController::createUrl('currentController/methodToCall')
'update' => '#two', //selector to update
'data' => array('one' => 'js:this.value'), //'js:javascript statement'
//leave out the data key to pass all form values through
)));
it generates
<select id="one" name="one">
<option value="">one</option>
<option value="1">two</option>
<option value="3">three</option>
</select>
But I need create below with hardcoded <option>
<select id="one" name="one">
<option value="">one</option>
<option value="1">two</option>
<option value="3">three</option>
<option value="0">Another option</option>
</select>
is this possible?
ahmed201
(Rifajas)
December 10, 2013, 12:05pm
2
mini998:
I have below code
echo CHtml::dropDownList('one', ((isset($data1)) ? $data1 : ""),CHtml::listData(Property::model()->findAll($criteria), 'id', 'name'), array(
'prompt' => ((isset($name1)) ? $name1 : "Empty"),
'id' => 'one',
'ajax' => array(
'type' => 'POST', //request type
'url' => CController::createUrl('dynamicList'), //url to call.
//Style: CController::createUrl('currentController/methodToCall')
'update' => '#two', //selector to update
'data' => array('one' => 'js:this.value'), //'js:javascript statement'
//leave out the data key to pass all form values through
)));
it generates
<select id="one" name="one">
<option value="">one</option>
<option value="1">two</option>
<option value="3">three</option>
</select>
But I need create below with hardcoded <option>
<select id="one" name="one">
<option value="">one</option>
<option value="1">two</option>
<option value="3">three</option>
<option value="0">Another option</option>
</select>
is this possible?
yes possible you can hardcode it. but if u need ajax with dropdown list u need to write ur own ajax functions too. so using yii way is the more efficient way.
mini998
(Ima Silva)
December 10, 2013, 12:20pm
3
Ok I found the solution to my problem
echo CHtml::dropDownList('one', ((isset($data1)) ? $data1 : ""),CHtml::listData(Property::model()->findAll($criteria), 'id', 'name')+array("0"=>"empty"), array(
'prompt' => ((isset($name1)) ? $name1 : "Empty"),
'id' => 'one',
'ajax' => array(
'type' => 'POST', //request type
'url' => CController::createUrl('dynamicList'), //url to call.
//Style: CController::createUrl('currentController/methodToCall')
'update' => '#two', //selector to update
'data' => array('one' => 'js:this.value'), //'js:javascript statement'
//leave out the data key to pass all form values through
)));
?>