skeeks / yii2-widget-dual-listbox
Dual Listbox Widget for Yii 2
Installs: 15
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Type:yii2-extension
Requires
This package is auto-updated.
Last update: 2024-10-29 04:47:47 UTC
README
Dual Listboxt for Yii framework 2.0.
Description
skeeks\widget\duallistbox\WidgetDualListbox widget is a Yii 2 wrapper for Bootstrap Dual Listbox.
Requirements
- Yii Version 2.0.0 or later
Usage
-
Add
skeeks/yii2-widget-dual-listbox
in your project'scomposer.json
, and let Composer configure your project."require": { "php": ">=5.4.0", "yiisoft/yii2": "*", "yiisoft/yii2-bootstrap": "*", "yiisoft/yii2-swiftmailer": "*", "skeeks/yii2-widget-dual-listbox": "dev-master" },
-
Use
skeeks\widget\duallistbox\WidgetDualListbox::widget()
in place ofyii\helpers\Html::listBox()
,yii\helpers\Html::activeListBox()
, oryii\widgets\ActiveField::listBox()
in your view.-
Replacing Html::listBox() using name and selection
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', ], ]); ?>
-
Replacing Html::activeListBox() using model and attribute
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', ], ]); ?>
-
Replacing ActiveField::listBox() using model and attribute
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', ], ]); ?>
-
-
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.
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.
Properties of skeeks\widget\duallistbox\WidgetDualListbox
-
name @var string
The input name.
-
selection @var array
The selected values.
-
model @var yii\base\Model
The model object.
-
attribute @var string
The attribute name.
-
items @var array
The option data items. The array keys are option values, and the array values are the corresponding option labels.
-
options @var array
The tag options for the listbox in terms of name-value pairs.
-
clientOptions @var array
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.
The first 6 properties correspond to the parameters used in Html::listBox()
, Html::activeListBox()
and ActiveField::listBox()
.
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()
.
SkeekS CMS (Yii2) — quickly, easily and effectively!
skeeks.com | cms.skeeks.com