I have quite a few boolean fields in my various tables. The customer would like the forms to use Yes/No radio buttons for each field instead of a checkbox.
What is the best way to go about doing this, such that the true boolean maps to yes radio button?
Thanks
Janice
Page 1 of 1
Boolean Yes/no Radio Buttons How do I create them
#2
Posted 09 October 2012 - 06:13 PM
You can use this on the view:
<?php echo CHtml::radioButton('name1', $model->attributeName); ?>
<?php echo CHtml::radioButton('name2', !$model->attributeName); ?>
You will still need to setup the labels, validation and handle the data received in the controller.
Rodrigo Coelho
Check my extension
giix: a code generator for Yii.
The complete beginner's study guide for the Yii Framework
Check my extension
giix: a code generator for Yii.

The complete beginner's study guide for the Yii Framework
#3
Posted 09 October 2012 - 06:31 PM
Like this?
<?php echo $form->radioButtonList($model, 'yourBooleanAttribute', array(1 => 'Yes', 0 => 'No'), array('separator' => '')); ?>
#4
Posted 09 October 2012 - 06:33 PM
I think that CActiveForm::radioButtonList can be a good choice.
http://www.yiiframew...ttonList-detail
http://www.yiiframew...ttonList-detail
$yesNo = array('0' => 'No', '1' => 'Yes');
echo $form->labelEx($model, 'name');
echo $form->radioButtonList($model, 'name', $yesNo);
echo $form->error($model, 'name');
#5
Posted 09 October 2012 - 06:54 PM
Agreed, guys. radioButtonList is a better choice.
Rodrigo Coelho
Check my extension
giix: a code generator for Yii.
The complete beginner's study guide for the Yii Framework
Check my extension
giix: a code generator for Yii.

The complete beginner's study guide for the Yii Framework
Share this topic:
Page 1 of 1

Help













