Returning Values From Tbbuttongroup In A Form

Hi - is it possible to use TbButtonGroup as a multiple select object, in a form, where the selected value is returned (along with other form values), when the form’s submit button is finally selected?

I’m trying the following. It’s to a point where the buttons exist on the page with their values, but these fail to be included when the form is finally submitted (via CHtml::submitButton)


  <div class="span8">

        <?php $this->widget('bootstrap.widgets.TbButtonGroup', array(

            'type' => 'primary',

            'toggle' => 'radio',

            'buttons' => array(

                array('label'=>'option 1', 'type'=>'info', 'htmlOptions'=>array('name'=>'button1', 'value'=>'1')),

                array('label'=>'option 2', 'type'=>'primary' 'htmlOptions'=>array('name'=>'button2', 'value'=>'2')),

                array('label'=>'option 3', 'type'=>'success', 'htmlOptions'=>array('name'=>'button3', 'value'=>'3')),

            ),

        )); ?>

      </div>

I’m wondering if this is possible. If so, where am I going wrong

Not sure if it can be done. But looking at your code that specific TbButtonGroup doesn’t look like it is actually attached to the form or model.

There may be an activeButtonGroup, or something similar in the Yii-Bootstrap. Just thoughts, haven’t used TB.

Create a hidden field


echo $form->hiddenfield($model, 'modelAttribute', array('id'=>'hiddenFieldId'));

And then for every button add a js function/command for an onClick event


<?php $this->widget('bootstrap.widgets.TbButtonGroup', array(

            'type' => 'primary',

            'toggle' => 'radio',

            'buttons' => array(

                array('label'=>'option 1', 'type'=>'info', 'htmlOptions'=>array('name'=>'button1', 'OnClick'=>'$("#hiddenFieldId").val("1");')),

                array('label'=>'option 2', 'type'=>'primary' 'htmlOptions'=>array('name'=>'button2', 'OnClick'=>'$("#hiddenFieldId").val("2");')),

                array('label'=>'option 3', 'type'=>'success', 'htmlOptions'=>array('name'=>'button3', 'OnClick'=>'$("#hiddenFieldId").val("3");'')),

            ),

        )); ?>



Hope it helps.