efureev/yii2-tagsinput

Bootstrap Tags Input is a jQuery plugin providing a Twitter Bootstrap user interface for managing tags.


Keywords
tags, tag, input, typeahead, yii2
License
MIT

Documentation

yii2-tagsinput

GitHub version Build Status Dependency Status Code Climate Test Coverage

without Model

var inputUsers = $('<input type="text">'),
    users = new Bloodhound({
        datumTokenizer: Bloodhound.tokenizers.obj.whitespace('title'),
        queryTokenizer: Bloodhound.tokenizers.whitespace,
        prefetch      : {
            url   : '/users.json',
            cache : false,
            filter: function (list) {
                return $.map(list, function (users) {
                    return {text: user.name};
                });
            }
        }
    });
hubs.initialize();

inputUsers.tagsinput({
    typeaheadjs: {
        displayKey: 'text',
        trimValue : true,
        valueKey  : 'text',
        name      : 'users',
        source    : users.ttAdapter()
    }
});

with Model

<?= $form->field($model, 'users', ['options' => [
    'class' => 'form-group',
]])->widget(
    \efureev\tagsinput\TagsInput::className(),
    [
        'preJS' => 'var users = new Bloodhound({
            datumTokenizer: Bloodhound.tokenizers.obj.whitespace("title"),
            queryTokenizer: Bloodhound.tokenizers.whitespace,
            prefetch : { url : "/users", cache : false,
                filter: function (list) {
                    return $.map(list, function (user) {
                        return {text: user.name};
                    });
                }
            }
        });',
        'clientOptions' => [
            'typeaheadjs' => [
                'displayKey' => 'text',
                'trimValue'  => true,
                'valueKey'   => 'text',
                'name'       => 'users',
                'source'     => new \yii\web\JsExpression('users.ttAdapter()')
            ]
        ]
    ]
);
?>

Tests

vendor/bin/phpunit