You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

components-combobox.asciidoc 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. ---
  2. title: ComboBox
  3. order: 16
  4. layout: page
  5. ---
  6. [[components.combobox]]
  7. = [classname]#ComboBox#
  8. ifdef::web[]
  9. [.sampler]
  10. image:{live-demo-image}[alt="Live Demo", link="http://demo.vaadin.com/sampler/#ui/data-input/multiple-value/combo-box"]
  11. endif::web[]
  12. [classname]#ComboBox# is a selection component allows selecting an item from a
  13. drop-down list. The component also has a text field area, which allows entering
  14. search text by which the items shown in the drop-down list are filtered. Common
  15. selection component features are described in
  16. <<dummy/../../../framework/components/components-selection#components.selection,"Selection
  17. Components">>.
  18. .The [classname]#ComboBox# Component
  19. image::img/combobox-basic.png[width=35%, scaledwidth=50%]
  20. [classname]#ComboBox# supports adding new items when the user presses
  21. kbd:[Enter].
  22. ifdef::web[]
  23. See <<dummy/../../../framework/components/components-selection#components.selection.newitems,"Allowing Adding New Items">>.
  24. endif::web[]
  25. [[components.combobox.filtering]]
  26. == Filtered Selection
  27. [classname]#ComboBox# allows filtering the items available for selection in the
  28. drop-down list by the text entered in the input box.
  29. [[figure.components.combobox.filter]]
  30. .Filtered Selection in [classname]#ComboBox#
  31. image::img/combobox-filtering.png[width=35%, scaledwidth=50%]
  32. Pressing kbd:[Enter] will complete the item in the input box. Pressing kbd:[Up] and kbd:[Down] arrow keys can be used for selecting an item from the drop-down list. The
  33. drop-down list is paged and clicking on the scroll buttons will change to the
  34. next or previous page. The list selection can also be done with the arrow keys
  35. on the keyboard. The shown items are loaded from the server as needed, so the
  36. number of items held in the component can be quite large. The number of matching
  37. items is displayed by the drop-down list.
  38. Filtering is enabled by setting a __filtering mode__ with
  39. [methodname]#setFilteringMode()#.
  40. [source, java]
  41. ----
  42. cb.setFilteringMode(FilteringMode.CONTAINS);
  43. ----
  44. See the http://demo.vaadin.com/book-examples-vaadin7/book#component.select.combobox.filtering[on-line example, window="_blank"].
  45. The modes defined in the [classname]#FilteringMode# enum are as follows:
  46. [parameter]#CONTAINS#:: Matches any item that contains the string given in the text field part of the
  47. component.
  48. [parameter]#STARTSWITH#:: Matches only items that begin with the given string.
  49. [parameter]#OFF# (default):: Filtering is by default off and all items are shown all the time.
  50. The above example uses the containment filter that matches to all items
  51. containing the input string. As shown in <<figure.components.combobox.filter>>
  52. below, when we type some text in the input area, the drop-down list will show
  53. all the matching items.
  54. [[components.combobox.css]]
  55. == CSS Style Rules
  56. [source, css]
  57. ----
  58. .v-filterselect { }
  59. .v-filterselect-input { }
  60. .v-filterselect-button { }
  61. // Under v-overlay-container
  62. .v-filterselect-suggestpopup { }
  63. .popupContent { }
  64. .v-filterselect-prevpage,
  65. .v-filterselect-prevpage-off { }
  66. .v-filterselect-suggestmenu { }
  67. .gwt-MenuItem { }
  68. .v-filterselect-nextpage,
  69. .v-filterselect-nextpage-off { }
  70. .v-filterselect-status { }
  71. ----
  72. In its default state, only the input field of the [classname]#ComboBox#
  73. component is visible. The entire component is enclosed in
  74. [literal]#++v-filterselect++# style (a legacy remnant), the input field has
  75. [literal]#++v-filterselect-input++# style and the button in the right end that
  76. opens and closes the drop-down result list has
  77. [literal]#++v-filterselect-button++# style.
  78. The drop-down result list has an overall
  79. [literal]#++v-filterselect-suggestpopup++# style. It contains the list of
  80. suggestions with [literal]#++v-filterselect-suggestmenu++# style. When there are
  81. more items that fit in the menu, navigation buttons with
  82. [literal]#++v-filterselect-prevpage++# and
  83. [literal]#++v-filterselect-nextpage++# styles are shown. When they are not
  84. shown, the elements have [literal]#++-off++# suffix. The status bar in the
  85. bottom that shows the paging status has [literal]#++v-filterselect-status++#
  86. style.