You are here

function elements_add_autocomplete in Elements 7

Same name and namespace in other branches
  1. 6 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 156

Code

function elements_add_autocomplete(&$element) {
  $extra = '';
  if (!empty($element['#autocomplete_path']) && drupal_valid_path($element['#autocomplete_path'])) {
    drupal_add_library('system', 'drupal.autocomplete');
    $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';
    $extra = '<input' . drupal_attributes($attributes) . ' />';
  }
  return $extra;
}