I did this in my custom module :
function hook_form_alter( &$form, &$form_state,$form_id ) {
if($form_id == 'views_exposed_form') {
$view = $form_state['view'];
if($view->name == 'your_view_name') {
$form['data']['#autocomplete_path'] = 'example/autocomplete';
}
}
}
'#autocomplete_path' => 'example/autocomplete' defines an autocomplete callback for our textfield.
When user types something into our textfield, Drupal sends a request via this url to send data you input and to receive suggestions via json if there are any.
To make Drupal aware of this path, let’s add it to the menu system(hook_menu):
$items['example/autocomplete'] = array(
'page callback' => '_module_name_autocomplete',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK
);
Now we need to create a _module_name_autocomplete function which will look for a suggestion and return it to the user.
function _module_name_autocomplete($string) {
$matches = array();
// Some fantasy DB table which holds cities
$return = db_select('webform_submitted_data', 'w')
->fields('w')
->condition('w.cid', 'your_component_id', '=')
->condition('w.data', '%' . db_like($string) . '%', 'LIKE')
->execute();
// add matches to $matches
foreach ($return as $row) {
$matches[$row->data] = check_plain($row->data);
}
// return for JS
drupal_json_output($matches);
}