I'd like some AJAX code built-in to the Drupal core. I've done this and gone one step further by creating an AJAX module that has a functional form_autocomplete() field type - that can be used on any form field.

The function has one extra parameter- $callback. This is a Drupal path to a callback function which will return the autocomplete results for the field to display. The results are returned as a pipe (|) delimitted list of strings.

Here's an example callback function I'm already using:

function recipe_autocomplete_page($string, $limit = 10) {
  $matches = array();
  $rs = db_query('SELECT name FROM {recipe_ingredient} WHERE name LIKE "%%%s%%" LIMIT %d', $string, $limit);
  while ($r = db_fetch_object($rs)) {
    $matches[] = $r->name;
  }
  echo implode('|', $matches);
}

CommentFileSizeAuthor
ajax.zip3.97 KBThox

Comments

Thox’s picture

Title: AJAX form_autocomplete() field » Ajax autocomplete field (ajax module)

Closed.

form_autocomplete() is now committed to core (see http://drupal.org/node/22519).