autocomplete_deluxe.api.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /**
  3. * @file
  4. * This contains documentation only.
  5. */
  6. /**
  7. * Using the Autocomplete Deluxe element.
  8. *
  9. * When you want to use the Autocomplete Deluxe element, you have to choose
  10. * between two types sources for the suggestion data: Ajax Callbacks or Lists.
  11. * You can set the source type by using the appropriate options:
  12. * - #autocomplete_deluxe_path expects a string with an url, that points to the
  13. * ajax callback. The response should be encoded as json (like for the core
  14. * autocomplete).
  15. * - #autocomplete_options needs an array in the form of an array (similar to
  16. * #options in core for selects or checkboxes): array('a', 'b', 'c') or
  17. * array(1 => 'a', 2 => 'b', 3 => 'c').
  18. *
  19. * Besides these two, there are four other options which autocomplete deluxe
  20. * accepts:
  21. * - #multiple Indicates whether the user may select more than one item. Expects
  22. * TRUE or FALSE, by default it is set to FALSE.
  23. * - #delimiter If #multiple is TRUE, then you can use this option to set a
  24. * seperator for multiple values. By default a string with the following
  25. * content will be used: ', '.
  26. * - #min_length Indicates how many characters must be entered
  27. * until, the suggesion list can be opened. Especially helpful, when your
  28. * ajax callback returns only valid suggestion for a minimum characters.
  29. * The default is 0.
  30. * - #not_found_message A message text which will be displayed, if the entered
  31. * term was not found.
  32. */
  33. function somefunction() {
  34. switch ($type) {
  35. case 'list':
  36. $element = array(
  37. '#type' => 'autocomplete_deluxe',
  38. '#autocomplete_options' => $options,
  39. '#multiple' => FALSE,
  40. '#min_length' => 0,
  41. );
  42. break;
  43. case 'ajax':
  44. $element = array(
  45. '#type' => 'autocomplete_deluxe',
  46. '#autocomplete_deluxe_path' => url('some_uri', array('absolute' => TRUE)),
  47. '#multiple' => TRUE,
  48. '#min_length' => 1,
  49. '#delimiter' => '|',
  50. '#not_found_message' => "The term '@term' will be added.",
  51. );
  52. break;
  53. }
  54. }