Index: modules/taxonomy.module =================================================================== RCS file: /cvs/drupal/drupal/modules/taxonomy.module,v retrieving revision 1.204 diff -u -F^f -r1.204 taxonomy.module --- modules/taxonomy.module 21 May 2005 21:32:54 -0000 1.204 +++ modules/taxonomy.module 22 May 2005 15:41:02 -0000 @@ -82,6 +82,11 @@ function taxonomy_menu($may_cache) { 'callback' => 'taxonomy_term_page', 'access' => user_access('access content'), 'type' => MENU_CALLBACK); + + $items[] = array('path' => 'taxonomy/autocomplete', 'title' => t('autocomplete taxonomy'), + 'callback' => 'taxonomy_autocomplete', + 'access' => user_access('access content'), + 'type' => MENU_CALLBACK); } else { if (is_numeric(arg(2))) { @@ -519,7 +524,7 @@ function taxonomy_node_form($type, $node } } $typed_string = implode(', ', $typed_terms) . (array_key_exists('tags', $terms) ? $terms['tags'][$vocabulary->vid] : NULL); - $result[] = form_textfield($vocabulary->name, "$name][tags][". $vocabulary->vid, $typed_string, 50, 100, t('A comma-separated list of terms describing this content (Example: funny, bungie jumping, "Company, Inc.").'), NULL, ($vocabulary->required ? TRUE : FALSE)); + $result[] = form_autocomplete($vocabulary->name, "$name][tags][". $vocabulary->vid, $typed_string, 50, 100, 'taxonomy/autocomplete/'. $vocabulary->vid, t('A comma-separated list of terms describing this content (Example: funny, bungie jumping, "Company, Inc.").'), NULL, ($vocabulary->required ? TRUE : FALSE)); } else { $ntterms = array_key_exists('taxonomy', $node) ? $terms : array_keys($terms); @@ -1259,4 +1264,25 @@ function _taxonomy_get_tid_from_term($te return $term->tid; } +/** + * Helper function for autocompletion + */ +function taxonomy_autocomplete($vid, $string = '', $limit = 10) { + $array = explode(',', $string); + $last_string = trim(array_pop($array)); + if ($last_string != '') { + $matches = array(); + $result = db_query_range("SELECT name FROM {term_data} WHERE vid = %d AND LOWER(name) LIKE LOWER('%%%s%%')", $vid, $last_string, 0, $limit); + while ($r = db_fetch_object($result)) { + if (count($array)) { + $matches[] = implode(', ', $array) .', '. check_plain($r->name); + } + else { + $matches[] = check_plain($r->name); + } + } + echo implode('|', $matches); + exit(); + } +} ?>