Hi all,
I have a problem implementing autocomlete. The situation is as following:
Table 1: Messages: with field ‘user_id_rec’
Table 2: Profiles: with fields ‘user_id’ and ‘compname’
In the create view of Messages id like to have the ‘user_id_rec’ as autocompleted field.
The list has to consist of the ‘compnames’ of the table profiles and the ‘user_id’ of the chosen name should be submitted when the save button is hit.
I tried to achieve this by following this tutorial. But i can’t get it to work. The field does appear on the form, but does not autocomplete.
I did the following:
created the file at step one and saved it to the extensions map.
added the code from step 2 to my Profiles model. I changed the sql there to:
$sql= ‘SELECT user_id ,compname AS label FROM users WHERE compname LIKE :name’;
added the code from step 3 to my profiles controller. I changed some code there too.
$users = Users::usersAutoComplete($term); changed too $users = Profiles::usersAutoComplete($term);
added the code from step 4 to my _form-file of messages and changed it to this:
<div class="row">
<?php
// Note: ext.MyAutoComplete is equivalent/shortcut to application.extensions.MyAutoComplete
// This means Look for protected/extensions/MyAutoComplete.php file
$this->widget('ext.myAutoComplete', array(
'model'=>$model,
'attribute'=>'user_id_rec',
'name'=>'compname',
'source'=>$this->createUrl('profiles/usersAutoComplete'), // Controller/Action path for action we created in step 4.
// additional javascript options for the autocomplete plugin
'options'=>array(
'minLength'=>'0',
),
'htmlOptions'=>array(
'style'=>'height:20px;',
),
)); ?>
</div>
i tried so many things the last hour, i can’t see it right anymore.
Some help would be appreciated
Thanks in advance!