2017 © Pedro Peláez
 

yii2-extension yii2-widget-dual-listbox

Dual Listbox Widget for Yii 2

image

skeeks/yii2-widget-dual-listbox

Dual Listbox Widget for Yii 2

  • Thursday, November 9, 2017
  • by skeeks-semenov
  • Repository
  • 1 Watchers
  • 0 Stars
  • 3 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

yii2-widget-dual-listbox

Dual Listboxt for Yii framework 2.0., (*1)

Description

skeeks\widget\duallistbox\WidgetDualListbox widget is a Yii 2 wrapper for Bootstrap Dual Listbox., (*2)

Requirements

  • Yii Version 2.0.0 or later

Usage

  1. Add skeeks/yii2-widget-dual-listbox in your project's composer.json, and let Composer configure your project., (*3)

    "require": {
        "php": ">=5.4.0",
        "yiisoft/yii2": "*",
        "yiisoft/yii2-bootstrap": "*",
        "yiisoft/yii2-swiftmailer": "*",
        "skeeks/yii2-widget-dual-listbox": "dev-master"
    },
    
  2. Use skeeks\widget\duallistbox\WidgetDualListbox::widget() in place of yii\helpers\Html::listBox(), yii\helpers\Html::activeListBox(), or yii\widgets\ActiveField::listBox() in your view., (*4)

    1. Replacing Html::listBox() using name and selection, (*5)

      use skeeks\widget\duallistbox\WidgetDualListbox;
      ...
      <?php
          $options = [
              'multiple' => true,
              'size' => 20,
          ];
          // echo Html::listBox($name, $selection, $items, $options);
          echo DualListbox::widget([
              'name' => $name,
              'selection' => $selection,
              'items' => $items,
              'options' => $options,
              'clientOptions' => [
                  'moveOnSelect' => false,
                  'selectedListLabel' => 'Selected Items',
                  'nonSelectedListLabel' => 'Available Items',
              ],
          ]);
      ?>
      
    2. Replacing Html::activeListBox() using model and attribute, (*6)

      use skeeks\widget\duallistbox\WidgetDualListbox;
      ...
      <?php
          $options = [
              'multiple' => true,
              'size' => 20,
          ];
          // echo Html::activeListBox($model, $attribute, $items, $options);
          echo WidgetDualListbox::widget([
              'model' => $model,
              'attribute' => $attribute,
              'items' => $items,
              'options' => $options,
              'clientOptions' => [
                  'moveOnSelect' => false,
                  'selectedListLabel' => 'Selected Items',
                  'nonSelectedListLabel' => 'Available Items',
              ],
          ]);
      ?>
      
    3. Replacing ActiveField::listBox() using model and attribute, (*7)

      use skeeks\widget\duallistbox\WidgetDualListbox;
      ...
      <?php
          $options = [
              'multiple' => true,
              'size' => 20,
          ];
          // echo $form->field($model, $attribute)->listBox($items, $options);
          echo $form->field($model, $attribute)->widget(WidgetDualListbox::className(),[
              'items' => $items,
              'options' => $options,
              'clientOptions' => [
                  'moveOnSelect' => false,
                  'selectedListLabel' => 'Selected Items',
                  'nonSelectedListLabel' => 'Available Items',
              ],
          ]);
      ?>
      
  3. Collect the user input in the server side, just as you do with a single Listbox with multiple selection. Note that the input value will be an array., (*8)

    If you find difficulty in handling the user input, please read A Sample Code which demonstrates how to use a dual listbox to the data in array format., (*9)

Properties of skeeks\widget\duallistbox\WidgetDualListbox

  1. name @var string, (*10)

    The input name., (*11)

  2. selection @var array, (*12)

    The selected values., (*13)

  3. model @var yii\base\Model, (*14)

    The model object., (*15)

  4. attribute @var string, (*16)

    The attribute name., (*17)

  5. items @var array, (*18)

    The option data items. The array keys are option values, and the array values are the corresponding option labels., (*19)

  6. options @var array, (*20)

    The tag options for the listbox in terms of name-value pairs., (*21)

  7. clientOptions @var array, (*22)

    The options for the Bootstrap Dual Listbox in terms of name-value pairs. See Initialzation parameters object section of the official documentation of Bootstrap Dual Listbox for details., (*23)

The first 6 properties correspond to the parameters used in Html::listBox(), Html::activeListBox() and ActiveField::listBox()., (*24)

Note that you have to use either name-selection pair or model-attribute pair. The former is for replacing Html::listBox() and the latter is for Html::activeListBox() and ActiveField::listBox()., (*25)


skeeks!
SkeekS CMS (Yii2) — quickly, easily and effectively!
skeeks.com | cms.skeeks.com, (*26)

The Versions

09/11 2017

dev-master

9999999-dev https://skeeks.com/

Dual Listbox Widget for Yii 2

  Sources   Download

GPL-3.0+

The Requires

 

by Semenov Alexander

yii2 yii 2 widget duallistbox dual-listbox