I am attempting to build a custom autocomplete function that works for a textfield in a module I am creating. I believe I have everything set up correctly, but the blue autocomplete circle does not appear in my text field. It is my understanding that autocomplete.js loads when an '#autocomplete_path' variable is put into a form item. Is that correct, or is there a setting I need to turn on? Here are the pertinent items.

Form Field

$form['title'] = array(
'#title' => t('Portfolio Title'),
'#type' => 'textfield',
'#autocomplete_path' => 'autocomplete/portfolio/client',
'#description' => t("Please give the portfolio item a title."),
'#size' => 50,
'#default_value' => $port_values['title'],
'#maxlength' => 255,
'#required' => TRUE,
);

Menu Item

$items['autocomplete/portfolio/clients/%'] = array(
'title' => 'Autocomplete Portfolio Client List',
'page callback' => 'portfolio_clients',
'page arguments' => array(3),
'access callback' => TRUE,
'access arguments' => array('access portfolio contentt'),
'type' => MENU_CALLBACK,
);

Callback Function

function portfolio_clients($string = '') {
$matches = array();
echo "SELECT id, name FROM {portfolio} WHERE LOWER(name) LIKE LOWER('%%".$string."%%')";
if($string && !is_numeric($string)) {

$result = db_query_range("SELECT id, name FROM {portfolio} WHERE LOWER(name) LIKE LOWER('%%%s%%')", $string, 0, 10);
while ($client = db_fetch_object($result)) {
$key = is_numeric($client->id) ? intval($client->id) : "0";
$matches[$key] = check_plain($client->name);
}
}

drupal_json($matches);
}

Any and all help is appreciated! Thanks!

Ben

Comments

portablecow’s picture

I'm having the same trouble...subscribing