Auto complete

hi guys, how do i implement auto complete in my form field : <?= $form->field($model,‘name’)->dropDownList(ArrayHelper::map(Locations::find()->all(),

       'id', 'name')) ?&gt;

jui\AutoComplete

u have to use kartik typehead

ref link: My link

thanks guys

when i looked fro the source code it showed a 404 error

use this its very nice widget. typehead

Hey Guys,

I’m also currently working with this and have a small problem.

So I post my question here instead of opening a new thread.

Lets say you have a user table and a field "firstname".

You want autocomplete "firstname"…

But of course it is possible that the firstname can occur more than once…

So you want to "group" the same firstnames to avoid having them multiple times in the auto complete list.

But somehow I’m not able to group the results?

Any hints?

For example I have following code in my Controller:




public function actionFirstnameList($q = null) {

	$query = new Query;      

	$query->select('firstname')

		->from(User::tableName())

		->where('firstname LIKE "%'.$q.'%"')

		->groupBy('firstname')

		->orderBy('firstname');


	$command = $query->createCommand();

	$data = $command->queryAll();


	$output = [];

	foreach ($data as $d) {

		$output[] = ['value' => $d['firstname']];

	}


	Yii::$app->response->format = Response::FORMAT_JSON;

	return $output;

}



But the result is the same with or without "group by"… And suggests?

Thanks and best regards

paste the generated query (from debug toolbar for example)

and part of not groupped datas.

Hey!

Thanks for quick reply.

I just found out the “problem” was actually no problem… ;)

It was a cached result.

In my view I changed ‘prefetch’ to ‘remote’ now the group by is working. ;)




echo $form->field($model, 'firstname')->widget(Typeahead::classname(), [

	'options' => ['placeholder' => 'Filter as you type ...'],

	'pluginOptions' => ['highlight'=>true],

	'dataset' => [

		[

			// 'prefetch' => Url::to(['user/firstname-list']),

			'remote' => Url::to(['user/firstname-list']),

			'limit' => 10

		]

	]

]);



Regards

i want to display all names in table movie crew members. how can i do that? i tried the following code but it didnt work. what should i do???

<?php

&#036;data =ArrayHelper::map(MovieCrewMembers::find()-&gt;all(),'id','name');


echo &#036;form-&gt;field(&#036;model, 'director_id')-&gt;widget(Typeahead::classname(), [


'options' =&gt; ['placeholder' =&gt; 'Filter as you type ...'],


'pluginOptions' =&gt; ['highlight'=&gt;true],


'dataset' =&gt; [


    [


        'local' =&gt;  &#036;data,


        'limit' =&gt; 10


    ]


]

]);?>

Whts ur error?

auto complete is not working. i can type in text field but values in database are not displayed

use select2 autocompete

TL didnt like it :( she insisted not to use select2