Chosen Ajax

Component ID

1894076

Component name

Chosen Ajax

Component type

module

Maintenance status

Development status

Component security advisory coverage

not-covered

Downloads

5884

Component created

Component changed

Component body

Chosen Ajax uses the Chosen jQuery plugin and a modified version of Ajax Chosen to make your autocomplete fields more user-friendly.

It improves Entity Reference fields by hiding brackets and id to the user.

Dependencies

How to use in Field UI

  1. Create (or edit an existing field) that can use Autocomplete as widget such as Entity Reference or Term reference
  2. Go to the field settings and check Apply Chosen to this field.
  3. Go to the Chosen section and change texts if needed.
  4. If the field is an Entity Reference, check the option Fix display.
  5. Most probably you don't need to change the Advanced settings unless you know what you're doing.

How to use with Form API

...
$form['my_chosen_ajax_field'] = array(
  '#title' => 'My chosen ajax field',
  '#type' => 'textfield',
  '#autocomplete_path' => 'path/to/options',
  '#chosen' => TRUE,
  '#chosen_ajax' => array(
    // You can skip these options if default values are ok.
    'options' => array(
      'placeholder_text' => t('Select a value'),
      'typing_placeholder' => t('You need to type more'),
      'searching_placeholder' => t('Searching for'),
    ),
    // Set this values to change output.
    // Field's value is automatically passed as last argument.
    'value callback' => 'my_fix_display_func',
    // Only if it's necessary.
    'value arguments' => array('some_arg'),
  ),
);
...

IMPORTANT NOTES

  • If the Fix display option does not work for Entity Reference fields, make sure your pattern is /(.+) ((d+))/ and NOT /"(.+) ((d+))"/ (they removed quotes at some point).