xpbl4/yii2-dependent-widget

Dependent Dropdown widget allow to create simple dropdown list

Installs: 12

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Language:JavaScript

Type:yii2-extension

v1.0.2 2023-07-02 22:16 UTC

This package is auto-updated.

Last update: 2024-09-30 01:49:09 UTC


README

Latest Version Software License Total Downloads

Dependent Dropdown widget allows to create dependent dropdown lists

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist xpbl4/yii2-dependent-widget "*"

or add

"xpbl4/yii2-dependent-widget": "*"

to the require section of your composer.json file.

Usage

Once the extension is installed, simply use it in your code by:

<?= Html::dropDownList('depend_field', '', ['first', 'second', 'third']); ?>
<?= \xpbl4\dependent\Dropdown::widget([
    'id' => 'exampleInput',
    'name' => 'test',
    'items' => ['one', 'two', 'three'],
    'options' => ['class' => 'form-control', 'prompt' => 'Select item...'],
    'pluginOptions' => [
        'url' => \yii\helpers\Url::toRoute(), /* return [items...] */
        'initialize' => true,
        'depends' => [
            'depend_id' => 'depend_field',
        ],
        'ajaxOptions' => [
            'delay' => 500
        ],
        'pagination' => [
            'limit' => 10
        ],
    ],
    'pluginEvents' => [
        'dependent:init' => new \yii\web\JsExpression('consoleEvent'),
        'dependent:change' => new \yii\web\JsExpression('consoleEvent'),
        'dependent:focus' => new \yii\web\JsExpression('consoleEvent'),
        'dependent:beforeSend' => new \yii\web\JsExpression('consoleEvent'),
        'dependent:success' => new \yii\web\JsExpression('consoleEvent'),
        'dependent:error' => new \yii\web\JsExpression('consoleEvent'),
        'dependent:afterChange' => new \yii\web\JsExpression('consoleEvent'),

    ]
]); ?>

<?= \xpbl4\dependent\Select2::widget([
    'id' => 'exampleInput',
    'name' => 'test',
    'items' => ['one', 'two', 'three'],
    'options' => ['class' => 'form-control', 'prompt' => 'Select item...'],
    'pluginOptions' => [
        'url' => \yii\helpers\Url::toRoute(), /* return [items...] */
        'initialize' => true,
        'depends' => [
            'depend_id' => 'depend_field',
        ],
        'ajaxOptions' => [
            'delay' => 500
        ],
        'pagination' => [
            'limit' => 10
        ],
    ],
    'pluginEvents' => [
        'dependent:init' => new \yii\web\JsExpression('consoleEvent'),
        'dependent:change' => new \yii\web\JsExpression('consoleEvent'),
        ...

        'select2:open' => 'function (e) { log("select2:open", e); }',
        'select2:close' => new JsExpression('function (e) { log("select2:close", e); }')
        ...
    ],
    'select2Options' => [
        'allowClear' => true,
        'closeOnSelect' => false,
        ... /* Options for Select2 plugin */
    ]
]); ?>