yii-cms/yii2-typeahead

There is no license information available for the latest version (0.2) of this package.

Typeahead widget for Yii2 framework.

Installs: 16 688

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 0

Open Issues: 0

Type:yii2-extension

0.2 2015-11-11 07:00 UTC

This package is auto-updated.

Last update: 2024-04-25 16:54:34 UTC


README

Typeahead widget for Yii2 framework.

            <?php echo Typeahead::widget([
                'id' => 'typeahead-id',
                'name' => 'typeahead-name',
                'clientOptions' => [
                    'displayKey' => 'value',
                    'templates' => [
                        'suggestion' => new JsExpression("function(data){ return '<p>' + data.value + '</p>'; }"),
                    ],
                ],
                'events' => [
                    'typeahead:selected' => new JsExpression(
                        'function(obj, datum, name) { window.location = datum.url; }'
                    ),
                ],
                'bloodhoundOptions' => [
                    'remote' => [
                        'url' => Url::to(['controller/action']) . '?q=%QUERY',
                        'ajax' => ['data' => [
                            'id' => $model->id,
                        ]],
                        'replace' => new JsExpression("
                            function(url, query) {
                                return url.replace('%QUERY', query);
                            }
                        "),
                        'filter' => new JsExpression("
                            function(list) {
                                return $.map(list, function(item) { return { value: item.name, url: item.url }; });
                            }
                        "),
                    ],
                ],
                'options' => ['class' => 'form-control', 'placeholder' => 'Title', 'autofocus' => true],
            ]);