2017 © Pedro Peláez
 

yii2-extension yii2-widget-checkbox-multiple

Input widget to render multiple select box

image

diiimonn/yii2-widget-checkbox-multiple

Input widget to render multiple select box

  • Thursday, April 9, 2015
  • by diiimonn
  • Repository
  • 3 Watchers
  • 5 Stars
  • 412 Installations
  • JavaScript
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 2 Versions
  • 1 % Grown

The README.md

yii2-widget-checkbox-multiple

Input widget to render multiple select box. Using jQuery ajax., (*1)

Installation

To install with composer:, (*2)

$ php composer.phar require diiimonn/yii2-widget-checkbox-multiple "dev-master"

or add, (*3)

"diiimonn/yii2-widget-checkbox-multiple": "dev-master"

to the require section of your composer.json file., (*4)

Usage

view:

...
use diiimonn\widgets\CheckboxMultiple;
use yii\helpers\Url;
...

= $form->field($model, 'books')->widget(CheckboxMultiple::className(), [
    'dataAttribute' => 'name',
    'scriptOptions' => [
        'ajax' => [
            'url' => Url::toRoute(['books']),
        ],
    ],
    'placeholder' => Yii::t('app', 'Select ...'),
]) ?>

or not use ActiveForm, (*5)

...
use diiimonn\widgets\CheckboxMultiple;
use yii\helpers\Url;
...

= CheckboxMultiple::widget([
    'model' => $model,
    'attribute' => 'books',
    'dataAttribute' => 'name',
    'scriptOptions' => [
        'ajax' => [
            'url' => Url::toRoute(['books']),
        ],
    ],
    'placeholder' => Yii::t('app', 'Select ...'),
]) ?>

Settings

  • data : array the select option data items. The array keys are option values, and the array values are the corresponding option labels. If not set this option the 'attribute' will be relation name.
  • dataAttribute : string attribute name in relation models if not set 'data'.
  • scriptOptions : array options for customize script settings.
  • placeholder : string
  • options : array options for widget tag.
  • spinnerOptions : array options for yii2-widget-spinner-canvas.

scriptOptions

  • templateItem : string, html
  • templateCheckbox : string, html
  • templateResultItem : string, html
  • templateInput : string, html
  • templateResultError : string, html
  • templateResultWarning : string, html
  • templatePlaceholder : string, html
  • warningMessage : string
  • errorMessage : string
  • defaultCheckbox :: boolean If 'true' and not selected items will be selected checkbox with empty value. Default 'true'.
  • limit : integer Max count selected items.
  • slimScroll : array
  • wait : integer Time out in millisecond before ajax request.

Customize scriptOptions example

...
'scriptOptions' => [
    'defaultCheckbox' => false,
    'limit' => 10,
    'templateItem' => Html::tag('li', Html::tag('span', '{text}') .
            Html::tag('span', Html::tag('span', '', [
                'class' => 'glyphicon glyphicon-remove',
            ]), [
                'class' => 'checkbox-multiple-remove-item',
            ]), [
                'class' => 'checkbox-multiple-item',
            ]),
    'templateInput' => Html::textInput('checkbox-multiple-input', '', [
            'class' => 'form-control input-sm',
        ]),
    'slimScroll' => [
        'color' => '#333',
        'railOpacity' => 0.5,
        'railColor' => '#666666',
    ],
],

controller:

...
use yii\db\Query;
...

public function actionBooks()
{
    Yii::$app->response->format = 'json';

    $json = new \stdClass();

    $query = new Query();
    $query->select([
        'id' => 'id',
        'text' => 'name'
    ]);
    $query->from(BookModel::tableName());

    if ($search = Yii::$app->request->post('search', '')) {
        $query->where(['like', 'username', $search]);
    }

    $query->orderBy([
        'name' => SORT_ASC
    ]);

    if ($itemsId = Yii::$app->request->post('itemsId', [])) {
        $query->andWhere(['not in', 'id', $itemsId]);
    }

    $query->limit(20);

    $command = $query->createCommand();
    $data = $command->queryAll();
    $json->results = array_values($data);

    return $json;
}

The Versions

09/04 2015

dev-master

9999999-dev https://github.com/diiimonn/yii2-widget-checkbox-multiple

Input widget to render multiple select box

  Sources   Download

The Requires

 

by Dmitriy Gavrilenko

extension yii2 jquery ajax widget multiple checkbox

23/02 2015

v1.0.0

1.0.0.0 https://github.com/diiimonn/yii2-widget-checkbox-multiple

Input widget to render multiple select box

  Sources   Download

The Requires

 

by Dmitriy Gavrilenko

extension yii2 jquery ajax widget multiple checkbox