You are here

function elements_add_autocomplete in Elements 6

Same name and namespace in other branches
  1. 7 elements.module \elements_add_autocomplete()

Return the autocompletion HTML for a form element.

Parameters

$element: The renderable element to process for autocompletion.

Return value

The rendered autocompletion element HTML, or an empty string if the field has no autocompletion enabled.

4 calls to elements_add_autocomplete()
theme_emailfield in ./elements.theme.inc
Returns HTML for an emailfield form element.
theme_searchfield in ./elements.theme.inc
Returns HTML for a searchfield form element.
theme_telfield in ./elements.theme.inc
Returns HTML for a telfield form element.
theme_urlfield in ./elements.theme.inc
Returns HTML for an urlfield form element.

File

./elements.module, line 116

Code

function elements_add_autocomplete(&$element) {
  $output = '';
  if (!empty($element['#autocomplete_path']) && menu_valid_path(array(
    'link_path' => $element['#autocomplete_path'],
  ))) {
    drupal_add_js('misc/autocomplete.js');
    $element['#attributes']['class'] .= ' form-autocomplete';
    $attributes = array();
    $attributes['type'] = 'hidden';
    $attributes['id'] = $element['#attributes']['id'] . '-autocomplete';
    $attributes['value'] = url($element['#autocomplete_path'], array(
      'absolute' => TRUE,
    ));
    $attributes['disabled'] = 'disabled';
    $attributes['class'] = 'autocomplete';
    $output = '<input' . drupal_attributes($attributes) . ' />';
  }
  return $output;
}