Class yii\bootstrap\ToggleButtonGroup

Inheritanceyii\bootstrap\ToggleButtonGroup » yii\bootstrap\InputWidget » yii\widgets\InputWidget
Uses Traitsyii\bootstrap\BootstrapWidgetTrait
Available since version2.0.6

ToggleButtonGroup allows rendering form inputs Checkbox/Radio toggle button groups.

You can use this widget in an \yii\bootstrap\yii\bootstrap\ActiveForm using the \yii\bootstrap\yii\widgets\ActiveField::widget() method, for example like this:

<?= $form->field($model, 'item_id')->widget(\yii\bootstrap\ToggleButtonGroup::class, [
    // configure additional widget properties here
]) ?>

See also http://getbootstrap.com/javascript/#buttons-checkbox-radio.

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$clientEvents array The event handlers for the underlying Bootstrap JS plugin. yii\bootstrap\BootstrapWidgetTrait
$clientOptions array The options for the underlying Bootstrap JS plugin. yii\bootstrap\BootstrapWidgetTrait
$encodeLabels boolean Whether the items labels should be HTML-encoded. yii\bootstrap\ToggleButtonGroup
$items array The data item used to generate the checkboxes. yii\bootstrap\ToggleButtonGroup
$labelOptions \yii\bootstrap\array, The HTML attributes for the label (button) tag. yii\bootstrap\ToggleButtonGroup
$type string Input type, can be: - 'checkbox' - 'radio' yii\bootstrap\ToggleButtonGroup

Public Methods

Hide inherited methods

MethodDescriptionDefined By
getView() yii\bootstrap\BootstrapWidgetTrait
init() Initializes the widget. yii\bootstrap\ToggleButtonGroup
renderItem() Default callback for checkbox/radio list item rendering. yii\bootstrap\ToggleButtonGroup
run() yii\bootstrap\ToggleButtonGroup

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
registerClientEvents() Registers JS event handlers that are listed in $clientEvents. yii\bootstrap\BootstrapWidgetTrait
registerPlugin() Registers a specific Bootstrap plugin and the related events yii\bootstrap\BootstrapWidgetTrait

Property Details

$encodeLabels public property

Whether the items labels should be HTML-encoded.

public boolean $encodeLabels true
$items public property

The data item used to generate the checkboxes. The array values are the labels, while the array keys are the corresponding checkbox or radio values.

public array $items = []
$labelOptions public property

The HTML attributes for the label (button) tag.

See also:

  • yii\bootstrap\Html::checkbox()
  • yii\bootstrap\Html::radio()
public \yii\bootstrap\array, $labelOptions = []
$type public property

Input type, can be:

  • 'checkbox'
  • 'radio'
public string $type null

Method Details

init() public method

Initializes the widget.

This method will register the bootstrap asset bundle. If you override this method, make sure you call the parent implementation first.

public void init ( )
renderItem() public method

Default callback for checkbox/radio list item rendering.

See also:

  • yii\bootstrap\Html::checkbox()
  • yii\bootstrap\Html::radio()
public string renderItem ( $index, $label, $name, $checked, $value )
$index integer

Item index.

$label string

Item label.

$name string

Input name.

$checked boolean

Whether value is checked or not.

$value string

Input value.

return string

Generated HTML.

run() public method

public void run ( )