How To Disable Individual Items In Chtml::radiobuttonlist

Is there a way to disable individual items in a radioButtonList?

Something like:




Chtml::radioButtonList(

   $name, 

   $select, 

   array(

      'item1'=>$data, 

      'item2'=>$data, 

      'item3'=>$data

   ), 

   array (

      'itemOptions' => array(

         'item1'=>array('disabled'=>true),

         'item2'=>array('disabled'=>true)

      )

   )

)



would be nice.

For now I disable all items, and then enable ones I need with javascript. Or the other way around.

Hi andrjeuibo, welcome to the forum.

Unfortunately, the current implementation of radio button list doesn’t seem to support your idea.

Please look at the API reference.

CHtml::radioButtonList

CHtml::activeRadioButtonList

In both of them, $data parameter is for a simple array of value-label pairs of items.

How would You suggest I accomplish this in Yii manner?

Should I use the Chtml::radioButton() instead? Or maybe there is a way I could access the items in the list (a placeholder, like in htmlOptions=>template, or $data, like in CGridView) when its being processed?

Probably I would use CHtml::radioButton in a loop, because I don’t like to think too much. But, yes, you can do whatever you think is decent in this situation. I think you may consider extending CHtml::radioButtonList.