Class yii\bootstrap4\ToggleButtonGroup

Inheritanceyii\bootstrap4\ToggleButtonGroup » yii\bootstrap4\InputWidget » yii\widgets\InputWidget
Uses Traitsyii\bootstrap4\BootstrapWidgetTrait

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

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

<?= $form->field($model, 'item_id')->widget(\yii\bootstrap4\ToggleButtonGroup::class, [
    'type' => \yii\bootstrap4\ToggleButtonGroup::TYPE_CHECKBOX
    'items' => [
        'fooValue' => 'BarLabel',
        'barValue' => 'BazLabel'
    ]
]) ?>

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\bootstrap4\BootstrapWidgetTrait
$clientOptions array The options for the underlying Bootstrap JS plugin. yii\bootstrap4\BootstrapWidgetTrait
$encodeLabels boolean Whether the items labels should be HTML-encoded. yii\bootstrap4\ToggleButtonGroup
$items array The data item used to generate the checkboxes. yii\bootstrap4\ToggleButtonGroup
$labelOptions \yii\bootstrap4\array, The HTML attributes for the label (button) tag. yii\bootstrap4\ToggleButtonGroup
$type string Input type, can be TYPE_CHECKBOX or TYPE_RADIO yii\bootstrap4\ToggleButtonGroup

Public Methods

Hide inherited methods

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

Protected Methods

Hide inherited methods

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

Constants

Hide inherited constants

ConstantValueDescriptionDefined By
TYPE_CHECKBOX 'checkbox' Checkbox type yii\bootstrap4\ToggleButtonGroup
TYPE_RADIO 'radio' Radio type yii\bootstrap4\ToggleButtonGroup

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\bootstrap4\Html::checkbox()
  • yii\bootstrap4\Html::radio()
public \yii\bootstrap4\array, $labelOptions = ['class' => ['btn''btn-secondary']]
$type public property

Input type, can be TYPE_CHECKBOX or TYPE_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\bootstrap4\Html::checkbox()
  • yii\bootstrap4\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 ( )
throws \yii\base\InvalidConfigException