[support] Autocomplete

Jeff Greenberg listmail.ayendesigns at gmail.com
Thu May 30 21:02:12 UTC 2013


In D7, I have added a field to the article content type. A taxonomy
reference with autocomplete. I need to customize the autocomplete behavior.

I tried the following:
1. hook_form_alter to change the autocomplete path
2. hook_menu to register the path as a callback
3. create the callback function and have it do a simple print

Prior to doing this, typing in the field would fire autocomplete as
expected. And I also see the communication in the console of firebug.
Having made the two changes, I see the new path in the correct place in the
form field, but nothing happens when I type in the field other than the
characters appearing...the logic isn't fired and firebug shows no
communication.

I also tried registering the original autocomplete path with a different
callback. Same result.

Below are the functions.

/**
 * Implements hook_menu().
 */
function my_article_menu() {
  $items['a/categories'] = array(
    'page callback' => 'my_article_autocomplete_callback',
    'page arguments' => array(1),
    'type' => MENU_CALLBACK,
  );

  return $items;
}
/**
 * Implements hook_form_alter().
 */
function my_article_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'article_node_form') {
    $form['field_a_categories']['und']['#autocomplete_path'] =
'a/categories';
  }
}

function my_article_autocomplete_callback($vocabulary_name) {
  print '***** The vocabulary is ' . $vocabulary_name;
}

-- 
---
drupal.org/user/367108
linkedin.com/in/jeffrgreenberg
accidentalcoder.com / ayendesigns.com
@accidentalcoder
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/support/attachments/20130530/a7834281/attachment.html 


More information about the support mailing list