问题
I have a radio button in my form using the following code
echo $form->input('Users.vote', array(
'type' => 'radio',
'label' => array('text' => __("form_vote", "true"), 'class' => 'vote'),
'options' => array('1' => 'a', '2' => 'b', '3' => 'c' ),
));
This is my model validation for vote
'vote' => array(
'rule' => 'inList', array(1,2,3),
'allowEmpty' => false,
'required' => true,
'message' => 'error_vote'
)
Problem is that it adds a * right next to the a, b and c choices. Here is a screengrab on what it looks like with the stars on all three choices. http://imageshack.us/photo/my-images/23/radiojpg.jpg/ I'd like the star to only be displayed on the label 'Vote'
Here is the html output
<div class="input radio required"><fieldset><legend>Vote</legend><input type="hidden" value="" id="UserVote_" name="data[User][vote]">
<input type="radio" value="1" id="UserVote1" name="data[User][vote]">
<label for="UserVote1">a<span class="red">*</span></label>
<input type="radio" value="2" id="UserVote2" name="data[User][vote]">
<label for="UserVote2">b<span class="red">*</span></label>
<input type="radio" value="3" id="UsertVote3" name="data[User][vote]">
<label for="Vote3">c<span class="red">*</span></label></fieldset></div>
回答1:
Have an attribute called legend with a name to group all radio
echo $form->input('Users.vote', array(
'type' => 'radio',
'legend' => 'Vote*',
'class' => 'vote',
'options' => array('1' => 'a', '2' => 'b', '3' => 'c' ),
));
回答2:
I don't prefer using legends so I added a label before the radio list:
<?php echo $this->Form->label('radioname', __('Label:', true), 'required'); ?>
Then adjusted the css for the new label and the radio button labels:
label.required:after {
color: #e32;
content: '*';
display:inline;
}
.radio label{
font-weight:normal;
}
.radio label:after{
display:none !important;
}
来源:https://stackoverflow.com/questions/9381495/cakephp-remove-stars-in-all-choices-in-a-radio-button