V
V
Victor Umansky2017-05-09 22:55:43
Yii
Victor Umansky, 2017-05-09 22:55:43

Yii2 AutoCompleate dubbing text input?

Hi all.
There is a search form, the first and second input I use the widget from the kartik \typeahead\Typeahead;. When I try to find a tow truck, I get dubbed, I would like to get rid of it.
An example of how it looks like:
dca51f093b04.jpg
This is a table where users save their specialty
DmBZ6aqcV5aVmP.pngalt="image"/>
controller

public function actionCategoryList($q = null)
    {
        $query = new Query();

        $query->select('title')
            ->from('profile_has_category')
            ->where('title LIKE "%' . $q . '%"')
            ->orderBy('title');
        $command = $query->createCommand();
        $data = $command->queryAll();
        $out = [];
        foreach ($data as $d) {
            $out[] = ['value' => $d['title']];
        }
        echo Json::encode($out);
    }

view
Typeahead::widget([
                'name' => 'Search[category]',
                'options' => ['placeholder' => 'Искать специальности ...'],
                'pluginOptions' => ['highlight' => true],
                'class' => 'search-input-spec',
                'dataset' => [
                    [
                        'datumTokenizer' => "Bloodhound.tokenizers.obj.whitespace('value')",
                        'display' => 'value',
                        //'prefetch' => $asset->baseUrl . '/samples/countries.json',
                        'remote' => [
                            'url' => Url::to(['search/category-list']) . '?q=%QUERY',
                            'wildcard' => '%QUERY'
                        ]
                    ]
                ]
            ]);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
AlikDex, 2017-05-09
@Uman

$query->select('title')
            ->from('profile_has_category')
            ->where('title LIKE "%' . $q . '%"')
            ->groupBy('title')
            ->orderBy('title');

Or
$query->select('DISTINCT title')
            ->from('profile_has_category')
            ->where('title LIKE "%' . $q . '%"')
            ->orderBy('title');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question