This is a module that uses the jquery tagit plugin to enable autocomplete and freetext on a text field of your choice. The module has an interface enabling multiple tagit fields per site. This implementation of tagit requires that you provide an autocomplete url. Since drupal comes with very few autocomplete urls by default, then useful autocompletes may only be possible by creating your own, therefore use of this module may be limited by access to or ability to create your own autocomplete.

Module sponsored by NZ Council for Educational Research

Some features of tagit which are an improvement over drupal default autocompletes:

  • Tagit provides 'chosen' type keyword entries for text fields to provide a supplement to the chosen module which applies only to select fields.
  • If you hit submit before the autocomplete finishes you do not get a jquery http error

To make this module work you will need to create your own custom autocomplete of the type:

function MYMODULE_keyword_autocomplete($string) {
  $matches = array();
  if ($string) {
      $result = db_query("SELECT keyword_name FROM {my_keyword_bank} 
        WHERE keyword_name LIKE :pattern1 
        OR keyword_name LIKE :pattern2
        ORDER BY keyword_name LIMIT 10", array(
            ':pattern1' => db_like($string) .'%',
            ':pattern2' => '%'. db_like($string) .'%'));
    
    foreach ($result as $rec) {
      $matches[] = check_plain($rec->keyword_name);
    }
  }
  
  drupal_json_output($matches);
}

Note that the autocomplete function can have any name but must be driven by a url that you would create in your module using hook_menu:

  $items[keyword/autocomplete'] = array(
    'title' => 'autocomplete',
    'page callback' => 'MYMODULE_keyword_autocomplete',
    'page arguments' => array(2),
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
  );

The page arguments in the above are necessary to transfer the $string.

The module currently has functionality for one dependent field which is transferred using parameter1.

Project Information

Downloads