I honestly did, what this and this tutorial told me, but somehow my autocomplete textfields still fire an ajax error. but to be more specific: the ajax error gives a 200 http response and a status OK, but no answer-text.
my setup is:
$form['field_new_verein_location_'.$i] = array(
'#type' => 'textfield',
'#title' => t('<a id="ds_region_new_verein_'.$field_id.'" style="color:black;text-decoration:none;">Neuer Verein Ort</a>'),
'#default_value' => '',
'#size' => 60,
'#maxlength' => 128,
'#required' => TRUE,
'#description' => t('description'),
'#autocomplete_path' => 'dsregion/autocomplete'
);
function ds_regions_menu(){
$items['dsregion/autocomplete']=array(
'title' => 'location auto complete',
'page callback' => '_dsregion/autocomplete',
'access arguments' => array('access region autocomplete'),
'type' => MENU_CALLBACK
);
return $items;
}
function _dsregion_autocomplete($string) {
$matches = array();
$result = db_select('ds_plz_ort','o')
->fields('o',array('ort'))
->condition('ort','%'.db_like($string).'%','LIKE')
->range(0,10)
->execute()
->fetchAllKeyed();
foreach($result as $row){
$matches[$row->ort]=check_plain($row->ort);
}
drupal_json_output($matches);
}