1

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);
}

1 Answer 1

2

You have a slight error in your page callback property for the menu item. You've got a string resembling a path in there instead of the name of the callback function.

Just change

'page callback' => '_dsregion/autocomplete'

to

'page callback' => '_dsregion_autocomplete'

Then clear Drupal's caches and you should be good to go.

1
  • I love you guys. I was already comparing my code with the ones from the tutorials twice, but I didn't see this. Thanks a lot!
    – alex
    Commented Mar 2, 2012 at 18:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.