Trying to include a text Autocomplete Widget in a compound field (more here) using the snipped below.. but the field does not autocomplete. What am I doing wrong?

  $element['contact_name'] = array(
    '#title' => t('Name'),
    '#type' => 'textfield',
    '#default_value' => $defaults['contact_name'],
    '#weight' => 2,
    '#size' => '100',
    '#max_length' => '255',
    '#widget_type' => 'autocomplete_widgets_flddata',
    '#autocomplete_match' => 'contains',
    '#autocomplete_case' => '0',
    '#widget_module' => 'autocomplete_widgets',
  • If you have firebug enabled, can you investigate the "Net" tab, to see what url is called to fetch the autocomple-data? And can you look if the response (by Drupal) is actual JSON autocomplete data? – berkes Sep 14 '11 at 8:43
  • please add a tag indicating your core version. I'm assuming it is 6 since you mention CCK. – Capi Etheriel Nov 4 '11 at 18:20

Ok, so if you're trying to do it through hook_form_alter, you have to read the documentation on altering CCK fields.

The short version: the CCK fields are processed after the form is built. If you want to change anything in them, you have to add a callback to $form['#after_build'] (but do not replace the array, just add to it). Then implement the function, change values in $form and return the $form.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.