wdmg/yii2-selectinput

Bootstrap3 SelectInput widget for Yii2

Installs: 32

Dependents: 7

Suggesters: 0

Stars: 1

Watchers: 2

Forks: 1

Open Issues: 0

Type:yii2-extension

1.0.5 2019-06-05 00:04 UTC

README

Progress Github all releases GitHub version Progress GitHub license

Yii2 SelectInput

SelectInput widget for Yii2

Requirements

Installation

To install the widget, run the following command in the console:

$ composer require "wdmg/yii2-selectinput"

Usage

Example of standalone widget:

<?php

use wdmg\widgets\SelectInput;
...

echo SelectInput::widget([
    'model' => $model,
    'attribute' => 'type',
    'items' => [
        'value' => 'Label',
        ...
    ],
    'options' => [
        'class' => 'form-control'
    ],
    'pluginOptions' => [
        'dropdownClass' => '.dropdown',
        'listClass' => '.dropdown-menu',
        'itemClass' => '.dropdown-item',
        'toggleClass' => '.btn .btn-default .dropdown-toggle',
        'toggleText' => 'Dropdown',
        'toggleCaret' => '<span class="caret"></span>',
        'toggleChange' => true
    ]
])

?>

Example of use with ActiveForm:

<?php

use wdmg\widgets\SelectInput;
...

$form = ActiveForm::begin();
...

echo $form->field($model, 'type')->widget(SelectInput::className(), [
    'items' => [
        'value' => 'Label',
        ...
    ],
    'options' => [
        'class' => 'form-control'
    ],
    'pluginOptions' => [
        'dropdownClass' => '.dropdown',
        'listClass' => '.dropdown-menu',
        'itemClass' => '.dropdown-item',
        'toggleClass' => '.btn .btn-default .dropdown-toggle',
        'toggleText' => 'Dropdown',
        'toggleCaret' => '<span class="caret"></span>',
        'toggleChange' => true
    ]
]);
...

ActiveForm::end();

?>

Options

SelectInput extends InputWidget so you can use any options available for this widget. In addition, you can use these custom options if necessary:

Name Type Default Description
options array ['class' => 'form-control'] Standard options for the input widget.
pluginOptions array ['dropdownClass' => '.dropdown', 'listClass' => '.dropdown-menu', 'itemClass' => '.dropdown-item', 'toggleClass' => '.btn .btn-default .dropdown-toggle', 'toggleText' => 'Dropdown', 'toggleCaret' => '<span class="caret"></span>', 'toggleChange' => true Plugin SelectInput options passed to js. Read more here (https://github.com/wdmg/bootstrap-selectinput).
items array ['value' => 'Label'] Array values with labels.

Status and version

  • v.1.0.5 - Update README.md. Update Yii2 version.