skeeks/yii2-tagsinput

yii2-tagsinput 是一个用于 [bootstrap-tagsinput](https://github.com/timschlechter/bootstrap-tagsinput) 和 [typeahead.js](https://twitter.github.io/typeahead.js/) 的 Yii 2 包装器

安装: 9

依赖者: 0

建议者: 0

安全: 0

星标: 0

关注者: 2

分支: 5

语言:HTML

类型:yii2-extension

1.1.0 2016-11-23 14:48 UTC

This package is auto-updated.

Last update: 2024-08-29 04:14:35 UTC


README

安装

通过 Composer

$ composer require avikarsha/yii2-tagsinput

或者添加

"avikarsha/yii2-tagsinput": "*"

到你的 composer.json 文件的 require 部分中。

用法

在你的视图文件中。

<?php
use avikarsha\tagsinput\TagsinputWidget;
?>

<?= $form->field($model, 'tags')->widget(TagsinputWidget::classname(), [
    'clientOptions' => [
        'trimValue' => true,
        'allowDuplicates' => false
    ]
]) ?>

<?php echo $form->field($model, 'places')->widget(TagsinputWidget::classname(), [
    'clientOptions' => [
        "itemValue" => 'name',
        "itemText" => 'name',
    ],
   'dataset' => [
        [
            'remote' => [
                'url' => Url::to(['get-countries']). '?q=%QUERY',
                'wildcard' => '%QUERY'
            ],
            'datumTokenizer' => "Bloodhound.tokenizers.obj.whitespace('name')",
            'displayKey' => 'name',
            'limit' => 10,
            'templates' => [
                'header' => '<h3 class="name">Country</h3>'
            ]
        ],
        [
            'remote' => [
                'url' => Url::to(['get-cities']). '?q=%QUERY',
                'wildcard' => '%QUERY'
            ],
            'datumTokenizer' => "Bloodhound.tokenizers.obj.whitespace('name')",
            'displayKey' => 'name',
            'limit' => 10,
            'templates' => [
                'header' => '<h3 class="name">City</h3>'
            ]
        ],
        [
            'remote' => [
                'url' => Url::to(['get-states']). '?q=%QUERY',
                'wildcard' => '%QUERY'
            ],
            'datumTokenizer' => "Bloodhound.tokenizers.obj.whitespace('name')",
            'displayKey' => 'name',
            'limit' => 10,
            'templates' => [
                'header' => '<h3 class="name">State</h3>'
            ]
        ]
    ]
]) ?>

更多选项,请访问: http://bootstrap-tagsinput.github.io/bootstrap-tagsinput/examples/