Yii Framework Forum: Yii - Add Another Attribute To Dropdownlist - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Yii - Add Another Attribute To Dropdownlist YII - Add another attribute to dropDownList Rate Topic: -----

#1 User is offline   chalist 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 46
  • Joined: 16-December 12

Posted 08 November 2013 - 09:42 AM

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 
/*
 * codeless documentation
 */
?>

@chalist
0

#2 User is offline   ORey 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,688
  • Joined: 20-April 09
  • Location:Moscow, Russia

Posted 08 November 2013 - 09:46 AM

<?php 

echo CHtml::activeDropDownList($model, 'City', array(1 => 'one', 2 => 'two', 3 => 'three', 4 => 'four')); 

?>

God is real unless declared as integer
0

#3 User is offline   chalist 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 46
  • Joined: 16-December 12

Posted 09 November 2013 - 12:56 AM

View PostORey, on 08 November 2013 - 09:46 AM, said:

<?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
<?php 
/*
 * codeless documentation
 */
?>

@chalist
0

#4 User is offline   Arno S 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 27
  • Joined: 16-October 12
  • Location:Zwolle, The Netherlands

Posted 09 November 2013 - 02:57 AM

View Postchalist, on 09 November 2013 - 12:56 AM, said:

Does you understand what I ask dude?
I need to add test attribute for dropdown


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.
0

#5 User is offline   chalist 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 46
  • Joined: 16-December 12

Posted 09 November 2013 - 03:45 AM

http://stackoverflow...rect=1#19862018

thanks dude
<?php 
/*
 * codeless documentation
 */
?>

@chalist
0

#6 User is offline   Shahcheraghean 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 478
  • Joined: 12-December 12
  • Location:Mashhad, IRAN

Posted 09 November 2013 - 10:20 AM

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.
www.shgn.ir
www.shgn.ir/yii-framework/
yii2.swsco.ir
In a world without any fences or walls,Who needs Gates or Windows!
0

#7 User is offline   Arno S 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 27
  • Joined: 16-October 12
  • Location:Zwolle, The Netherlands

Posted 09 November 2013 - 03:37 PM

View Postchalist, on 09 November 2013 - 03:45 AM, said:



Oke, nice, I can't read code then.. Did it work?
0

#8 User is offline   chalist 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 46
  • Joined: 16-December 12

Posted 09 November 2013 - 04:28 PM

View PostShahcheraghean, on 09 November 2013 - 10:20 AM, said:

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 :D
the codes in stackoverflow works perfect :)
I set another attribute to all option tag with this method
<?php 
/*
 * codeless documentation
 */
?>

@chalist
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users