hkai
(Huangkai31)
June 20, 2009, 2:14pm
1
echo CHTML::activeRadioButtonList($form, "options", array("1"=>"Boston", "2"=>"Newton", "3"=>"Other") );
It's output is
<input id="ytCommandForm_options" type="hidden" value="" name="CommandForm[options]" /><input id="CommandForm_options_0" value="1" type="radio" name="CommandForm[options]" /> <label for="CommandForm_options_0">Boston</label><br/>
<input id="CommandForm_options_1" value="2" type="radio" name="CommandForm[options]" /> <label for="CommandForm_options_1">Newton</label><br/>
<input id="CommandForm_options_2" value="3" type="radio" name="CommandForm[options]" /> <label for="CommandForm_options_2">Other</label>
However, I don't want to use <label> tag, I'd rather use <span>, How can I do this?
My solution is completely copy over the 3 functions from CHTML and made my own version, but it'll causing troubles when I upgrade, so I'd rather do it in a better way. Please suggest.
xx666xx
(Jerryablan)
June 20, 2009, 7:21pm
2
You should try to avoid copying over core classes in the Yii framework.
You should always subclass.
class MyHTML extends CHtml
{
public static function activeRadioButtonList( ... )
{
}
}
hkai
(Huangkai31)
June 21, 2009, 2:10am
3
Thanks, Jerry. I did my own MyHtml extends CHtml and override 3 functions.
The issue is: although in $htmlOptions there's template,seperator etc. , it's not flexible enough to support another tag.
I tried to use "template"=>"{input}<span>{label}</span>" but it still get a <label> tag in {label}.
Hope to get the developer's attention on this to improve it later.
hkai
(Huangkai31)
June 21, 2009, 3:08am
4
Here's what I do to solve it
public static function myActiveRadioButtonList($model,$attribute,$data,$htmlOptions=array()){
$result= parent::activeRadioButtonList($model,$attribute,$data,$htmlOptions);
$result= str_replace("<label", "<span", $result);
$result= str_replace("</label", "</span", $result);
return $result;
}
And I hope it can be done like this
echo CHtml::activeRadioButtonList($form, $option_name, array("1","2"), true),
array("template"=>"{input}<span>{label}</span>",
"separator"=>" "
)
);
qiang
(Qiang Xue)
June 21, 2009, 3:12am
5
Not sure why you want to use span instead of label… Using label allows you to click on it to select the corresponding radio.
hkai
(Huangkai31)
June 21, 2009, 5:53am
6
Need to keep the 4 radio buttons in one line and label has a css of width: 100px
qiang
(Qiang Xue)
June 21, 2009, 12:33pm
7
Why not change the css style for labels?
hkai
(Huangkai31)
June 22, 2009, 2:29am
8
What I hope is the template in htmlOptions to be more flexible.
There's more than 3 ways to do that: CSS, str_replace, Table layout etc.
But the best way I think is by improving the template parameter so it'll be more flexible.
qiang
(Qiang Xue)
June 22, 2009, 12:44pm
9
The problem with your proposal is that we would have trouble generating a label tag which requires "for" attribute to contain the target id.