定制 diiimonn/yii2-widget-checkbox-multiple 二次开发

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

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

diiimonn/yii2-widget-checkbox-multiple

最新稳定版本:v1.0.0

Composer 安装命令:

composer require diiimonn/yii2-widget-checkbox-multiple

包简介

Input widget to render multiple select box

README 文档

README

Input widget to render multiple select box. Using jQuery ajax.

Installation

To install with composer:

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

or add

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

to the require section of your composer.json file.

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

...
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;
}

统计信息

  • 总下载量: 855
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 3
  • Forks: 3
  • 开发语言: JavaScript

其他信息

  • 授权协议: Unknown
  • 更新时间: 2015-02-03

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固