I was looking for the autocomplete CCK widget in Drupal 7, but I've seen that it's available for taxonomy only.
Is there a way to have it again?
I don't want a vocabulary for my field.

Comments

nevets’s picture

Why don't you want a vocabulary?

upupax’s picture

Cause they are just time slot (i.e. 10:00-10:45, 10:00-10:30).
I don't need them to be categorized, and I don't want drupal generates a page for each term.

nevets’s picture

You could use a list (text) and a select list for the element.

upupax’s picture

I could, but then I should manually add values from the backend to let user select them.
With autocomplete, new values would be automatically added.

nevets’s picture

Auto complete in this case would need a custom input (it needs somewhere to store the existing data).

upupax’s picture

Sorry, I was totally wrong.
I thought drupal 6.x had autocomplete for simple textfield too, but it didn't.
I've checked a site with a previous version, and neither there I could find this option.
So, I think I only dreamed about it! :)

rajatgusain’s picture

At present no module is available for CCK autocomplete field but you can achieve this by custom code :
Step 1 : use hook_form_alter((&$form, &$form_state, $form_id)
create case for your form_id
Step 2 : Add '#autocomplete_path' to the field where you want to add autocomplete functionality.

take reference of code given below :-

$form['autocomplete_textfield'] = array(
'#title' => t("Autocomplete Textfield"),
'#type' => 'textfield',
'#autocomplete_path' => 'autocomplete/example/textfield'
);

Step 3 :- and in hook_menu() :-

$items['autocomplete/example/textfield'] = array(
'page callback' => 'autocomplete_example_textfield',
'access callback' => TRUE,
'weight' => 1,
);

Step 4 :- now define the callback function.

function autocomplete_example_textfield ($string) {
$items = array();

$query = db_select('node', 'n');
$value = $query->fields('n', array('nid', 'title'));
$value = $query->condition(db_and()->condition('n.status', 1)->condition('title', '%' . db_like($string) . '%', 'LIKE'))
->orderRandom()
->execute();
$data = array();
$i = 0;
foreach ($value as $val) {
$items[$val->nid] = check_plain($val->title);
}
print drupal_json_output($items);
exit();
}

I hope this will help you.
Good Luck !
Cheers !

chrsc’s picture

Your post was very helpful, thanks!

nevets’s picture

Of course one could use a node reference field from the references module.

drupalnesia’s picture

For those who visit this page by Google, see: http://drupal.org/project/autocomplete_widgets