定制 softark/yii2-dual-listbox 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

softark/yii2-dual-listbox

Composer 安装命令:

composer require softark/yii2-dual-listbox

包简介

Bootstrap Dual Listbox Widget for Yii 2

README 文档

README

Dual Listboxt for Yii framework 2.0.

Description

softark\duallistbox\DualListbox widget is a Yii 2 wrapper for Bootstrap Dual Listbox.

It works with bootstrap 3, 4, or 5

Requirements

  • Yii Version 2.0.0 or later
  • yii2-bootstrap, yii2-bootstrap4 or yii2-bootstrap5
  • istvan-ujjmeszaros/bootstrap-duallistbox v.3.0.x or v.4.0.x

Usage

  1. Add softark/yii2-dual-listbox and istvan-ujjmeszaros/bootstrap-duallistbox in your project's composer.json, and let Composer configure your project.

    • You have to use a different version of istvan-ujjmeszaros/bootstrap-duallistbox depending on the bootstrap version.
    • For bootstrap 3, use ~3.0.0 :
    "require": {
        "php": ">=7.0.0",
        "yiisoft/yii2": "*",
        "yiisoft/yii2-bootstrap": "*",
        "istvan-ujjmeszaros/bootstrap-duallistbox": "~3.0.0",
        "softark/yii2-dual-listbox": "dev-master"
    },
    • For bootstrap 4 and 5, use ~4.0.0:
    "require": {
        "php": ">=7.0.0",
        "yiisoft/yii2": "*",
        "yiisoft/yii2-bootstrap4": "*", // OR
        "yiisoft/yii2-bootstrap5": "*",
        "istvan-ujjmeszaros/bootstrap-duallistbox": "~4.0.0",
        "softark/yii2-dual-listbox": "dev-master"
    },
  2. Use softark\duallistbox\DualListbox::widget() in place of yii\helpers\Html::listBox(), yii\helpers\Html::activeListBox(), or yii\widgets\ActiveField::listBox() in your view.

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

      use softark\duallistbox\DualListbox;
      ...
      <?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

      use softark\duallistbox\DualListbox;
      ...
      <?php
          $options = [
              'multiple' => true,
              'size' => 20,
          ];
          // echo Html::activeListBox($model, $attribute, $items, $options);
          echo DualListbox::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

      use softark\duallistbox\DualListbox;
      ...
      <?php
          $options = [
              'multiple' => true,
              'size' => 20,
          ];
          // echo $form->field($model, $attribute)->listBox($items, $options);
          echo $form->field($model, $attribute)->widget(DualListbox::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.

    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 softark\duallistbox\DualListbox

  1. name @var string

    The input name.

  2. selection @var array

    The selected values.

  3. model @var yii\base\Model

    The model object.

  4. attribute @var string

    The attribute name.

  5. items @var array

    The option data items. The array keys are option values, and the array values are the corresponding option labels.

  6. options @var array

    The tag options for the listbox in terms of name-value pairs.

  7. 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().

Notice

For some reason, Bootstrap Dual Listbox doesn't work in mobile device browsers, and so you can not use this widget for them.

Consider using checkbox list instead.

History

  • Version 1.0.0 (2016-01-12)
    • Tested on Yii 2.0.6
  • Version 1.0.1 (2020-09-18)
    • Supports both bootstrap3 and bootstrap4
  • Version 1.0.2 (2022-09-08)
    • Supports also bootstrap5

softark/yii2-dual-listbox 适用场景与选型建议

softark/yii2-dual-listbox 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 151.3k 次下载、GitHub Stars 达 20, 最近一次更新时间为 2016 年 01 月 12 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「widget」 「yii2」 「duallistbox」 「yii 2」 「dual-listbox」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 softark/yii2-dual-listbox 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 softark/yii2-dual-listbox 我们能提供哪些服务?
定制开发 / 二次开发

基于 softark/yii2-dual-listbox 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 151.3k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 20
  • 点击次数: 24
  • 依赖项目数: 9
  • 推荐数: 0

GitHub 信息

  • Stars: 20
  • Watchers: 4
  • Forks: 10
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2016-01-12