chalist
(Mohammad Molana)
November 8, 2013, 2:42pm
1
I will to add another attribute to dropDownList.
I will a dropdown list like this with Yii dropDownList:
<select name="city" id="city">
<option value="1" test="123">one</option>
<option value="2" test="234">two</option>
<option value="3" test="345">three</option>
<option value="4" test="456">four</option>
</select>
I will add test attribute to option tags.
Default Yii dropDownList is:
<?php
echo CHtml::activeDropDownList('City', 'City', array(1 => 'one', 2 => 'two'));
?>
How I can do this?
<?php
echo CHtml::activeDropDownList($model, 'City', array(1 => 'one', 2 => 'two', 3 => 'three', 4 => 'four'));
?>
chalist
(Mohammad Molana)
November 9, 2013, 5:56am
3
<?php
echo CHtml::activeDropDownList($model, 'City', array(1 => 'one', 2 => 'two', 3 => 'three', 4 => 'four'));
?>
Does you understand what I ask dude?
I need to add test attribute for dropdown
Hommer
(Arno Slatius)
November 9, 2013, 7:57am
4
Going over the code in CHtml I’d say it can’t be done. You can add any attribute to the Select, but the options are generated based on the list you supply and they’re converted to an option list somewhere at the end of CHtml::listOptions() and it creates a limited set of attributes on which you cannot add your own.
It can be done of course if you extends CHtml and overrule the listOptions() function if you realy need it.
shgninc
(Shgninc)
November 9, 2013, 3:20pm
6
My dear friend this is your answer.
the dropdownlist have a parameter, named $htmlOptions which you can add the extra options to it, But those options will apply just to select tag.
Maybe you should implement that with CHtml::tag(), But the best way is you mentioned in stackoverflow.
Hommer
(Arno Slatius)
November 9, 2013, 8:37pm
7
Oke, nice, I can’t read code then… Did it work?
chalist
(Mohammad Molana)
November 9, 2013, 9:28pm
8
My dear friend this is your answer.
the dropdownlist have a parameter, named $htmlOptions which you can add the extra options to it, But those options will apply just to select tag.
Maybe you should implement that with CHtml::tag(), But the best way is you mentioned in stackoverflow.
thanks my phpdeveloper friend in forum
the codes in stackoverflow works perfect
I set another attribute to all option tag with this method