You are here

DEVELOPER.txt in Autocomplete Limit Length 7

Developers can specify a per form-element minimum autocomplete length by
setting the data-limit attribute on the element in question. If found,
the module will use this value rather than the global value set via the
admin page.

Here is a simple example for a standard textfield element.

/**
 * Implements hook_form_alter().
 */
function example_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'test-form') {
    $form['element']['#attributes']['data-limit'] = 7;
  }
}


Note that not all autocomplete fields have the same form element structure.
For example, taxonomy term reference fields use a sub-element:

/**
 * Implements hook_form_alter().
 */
function example_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'test-form') {
    $form['element'][LANGUAGE_NONE]['#attributes']['data-limit'] = 3;
  }
}

File

DEVELOPER.txt
View source
  1. Developers can specify a per form-element minimum autocomplete length by
  2. setting the data-limit attribute on the element in question. If found,
  3. the module will use this value rather than the global value set via the
  4. admin page.
  5. Here is a simple example for a standard textfield element.
  6. /**
  7. * Implements hook_form_alter().
  8. */
  9. function example_form_alter(&$form, &$form_state, $form_id) {
  10. if ($form_id == 'test-form') {
  11. $form['element']['#attributes']['data-limit'] = 7;
  12. }
  13. }
  14. Note that not all autocomplete fields have the same form element structure.
  15. For example, taxonomy term reference fields use a sub-element:
  16. /**
  17. * Implements hook_form_alter().
  18. */
  19. function example_form_alter(&$form, &$form_state, $form_id) {
  20. if ($form_id == 'test-form') {
  21. $form['element'][LANGUAGE_NONE]['#attributes']['data-limit'] = 3;
  22. }
  23. }