Difference between #1 and #3 of
Custom Autocomplete Display and Value Submission

Changes

Title unchanged

Custom Autocomplete Display and Value Submission

Category unchanged

How-tos

Yii version unchanged

Tags unchanged

tutorial, autocomplete, jui

Content changed

[...]
2. Once user selects an item in the dropdown list and fill a hidden box with the id of the selected item for submission

##Making the right choice
To setup the autocomplete was a very straight forward operation, but I couldn't figure out how to get values from a custom JSON response and then fill the correspondent hidden fields.

CAutoComplete does ha
sve a way to do it, but I wanted to use CJuiAutoComplete to get all the cool features of its JQuery UiI and by looking at his code there was no method chain, something that is required to work with custom JSON responses as we need to override some methods.

##My Solution
[...]
Now that we have our beautiful widget that handles method chain in our Autocomplete, let's assume a couple of things:

* We saved our class
onto a folder in our application -folder - ie protected/extensions * We have a hidden INPUT HTML element with model's attribute_id * We have created an action on our testController named autocomplete that returns a JSON object onf the following format: ```php // This function will echo a JSON object // onf this format:
// [{id:id, name: 'name'}]
public function actionAutocomplete(){
[...]
'value' => $model->isNewRecord ? '': $model->attribute_value,
'options' => array(
'min
CharsLength'=>3,
'autoFill'=>false,
'focus'=> 'js:function( event, ui ) {
$( "#test_autocomplete" ).val( ui.item.name );
return false;
}',
[...]
12 0
18 followers
Viewed: 61 611 times
Version: 1.1
Category: How-tos
Written by: Antonio Ramirez
Last updated by: SebK
Created on: Jul 14, 2011
Last updated: 12 years ago
Update Article

Revisions

View all history