somov/yii2-select2-widget

具有 Bootstrap 主题功能的 Yii2 Select2 插件

安装: 9

依赖项: 0

建议者: 0

安全: 0

星级: 0

关注者: 0

分支: 6

语言:CSS

类型:yii2-extension

0.1.2.1 2021-10-10 15:14 UTC

This package is not auto-updated.

Last update: 2024-09-24 04:15:08 UTC


README

Latest Version Software License Build Status Coverage Status Quality Score Total Downloads

Select2 提供了一个可定制的选择框,支持搜索、标签、远程数据集、无限滚动以及许多其他常用选项。

安装

通过 Composer

$ composer require 2amigos/yii2-select2-widget

用法

小部件有两种类型,一种用于经典版,另一种用于 Bootstrap。除了需要一些调整的 Bootstrap 小部件外,其他小部件的配置主要通过 clientOptionsclientEvents 完成。这些属性分别持有插件的配置及其事件。

因此,我们强烈建议您访问 Select2 文档 以获取 Select2 上的可用选项,以及 Select2 Bootstrap 主题 以检查与该主题相关的所有可能的显示选项。

注意 我们正在创建一个网站,该网站将展示所有我们的小部件,包括这个。以下是一些基本示例,以帮助您开始。网站上的演示将更加全面,将展示所有可能的配置选项。

使用 Select2Widget

use dosamigos\select2\Select2:


// with \yii\bootstrap\ActiveForm;
echo $form
    ->field($model, 'attribute')
    ->widget(
        Select2::class, 
        [
            'items' => $data, // $data should be the same as the items provided to a regular yii2 dropdownlist
            'clientOptions' => ['theme' => 'classic']
        ]
    );
    
// as widget 
echo Select2::widget([
    'name' => 'my-name',
    'value' => 'my-value',
    'clientOptions' => [
        'maximumInputLength' => 20
    ]
]); 

使用 Select2BootstrapWidget

use dosamigos\select2\Select2Bootstrap:

// displaying the select2 with prepended addon
echo $form
    ->field($model, 'attribute')
    ->widget(
        Select2Bootstrap::class, 
        [
            'items' => $data, // $data should be the same as the items provided to a regular yii2 dropdownlist
            'template' => '<div class="input-group">' .
                  '<span class="input-group-btn">' .
                  '<button class="btn btn-default" type="button" data-select2-open="multi-prepend-append">' .
                  'State' .
                  '</button>' .
                  '</span>' .
                  '{input}' .
                   '<span class="input-group-addon">Append</span>' .
                   '</div>'
        ]
    );
    
// as widget 
echo Select2Bootstrap::widget([
    'name' => 'my-name',
    'value' => 'my-value',
    'clientOptions' => [
        'maximumInputLength' => 20
    ]
]); 

测试

$ phpunit

使用代码修复器

我们添加了一个 PHP 代码修复器以标准化我们的代码。它包括 Symfony、PSR2 以及一些贡献者的规则。

./vendor/bin/php-cs-fixer fix ./src --config .php_cs

贡献

有关详细信息,请参阅 CONTRIBUTING

鸣谢

许可证

BSD 许可证 (BSD)。有关更多信息,请参阅 许可证文件


定制软件 | 网页和移动开发
www.2amigos.us