You are here

function autocomplete_widgets_json in Autocomplete Widgets for Text and Number Fields 6

Same name and namespace in other branches
  1. 7 autocomplete_widgets.module \autocomplete_widgets_json()

Menu callback; Retrieve a pipe delimited string of autocomplete suggestions.

1 string reference to 'autocomplete_widgets_json'
autocomplete_widgets_menu in ./autocomplete_widgets.module
Implementation of hook_menu().

File

./autocomplete_widgets.module, line 202
Provides autocomplete widgets for CCK Text and Number fields.

Code

function autocomplete_widgets_json($type_name, $field_name, $string = '') {
  module_load_include('inc', 'autocomplete_widgets', 'autocomplete_widgets.common');
  $field = content_fields($field_name, $type_name);
  $match = isset($field['widget']['autocomplete_match']) ? $field['widget']['autocomplete_match'] : 'contains';
  $matches = array();
  $options = _autocomplete_widgets_get_options($field, $string, $match, NULL, 10);
  foreach ($options as $key => $value) {

    // Add a class wrapper for a few required CSS overrides.
    $matches[$value] = '<div class="reference-autocomplete">' . check_plain($value) . '</div>';
  }
  drupal_json($matches);
}