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-optiongroup.asciidoc 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. ---
  2. title: OptionGroup
  3. order: 19
  4. layout: page
  5. ---
  6. [[components.optiongroup]]
  7. = [classname]#OptionGroup#
  8. ifdef::web[]
  9. [.sampler]
  10. image:{live-demo-image}[alt="Live Demo", link="http://demo.vaadin.com/sampler/#ui/data-input/multiple-value/option-group"]
  11. endif::web[]
  12. [classname]#OptionGroup# is a selection component that allows selection from a
  13. group of radio buttons in single selection mode. In multiple selection mode, the
  14. items show up as check boxes. The common selection component features are
  15. described in
  16. <<dummy/../../../framework/components/components-selection#components.selection,"Selection Components">>.
  17. [[figure.components.optiongroup]]
  18. .Option Button Group in Single and Multiple Selection Mode
  19. image::img/optiongroup-basic.png[width=45%, scaledwidth=70%]
  20. Option group is by default in single selection mode. Multiple selection is
  21. enabled with [methodname]#setMultiSelect()#.
  22. [source, java]
  23. ----
  24. // A single-select radio button group
  25. OptionGroup single = new OptionGroup("Single Selection");
  26. single.addItems("Single", "Sola", "Yksi");
  27. // A multi-select check box group
  28. OptionGroup multi = new OptionGroup("Multiple Selection");
  29. multi.setMultiSelect(true);
  30. multi.addItems("Many", "Muchos", "Monta");
  31. ----
  32. <<figure.components.optiongroup>> shows the [classname]#OptionGroup# in both
  33. single and multiple selection mode.
  34. You can also create check boxes individually using the [classname]#CheckBox#
  35. class, as described in
  36. <<dummy/../../../framework/components/components-checkbox#components.checkbox,"CheckBox">>.
  37. The advantages of the [classname]#OptionGroup# component are that as it
  38. maintains the individual check box objects, you can get an array of the
  39. currently selected items easily, and that you can easily change the appearance
  40. of a single component.
  41. ifdef::web[]
  42. [[components.optiongroup.disabling]]
  43. == Disabling Items
  44. You can disable individual items in an [classname]#OptionGroup# with
  45. [methodname]#setItemEnabled()#. The user can not select or deselect disabled
  46. items in multi-select mode, but in single-select mode the use can change the
  47. selection from a disabled to an enabled item. The selections can be changed
  48. programmatically regardless of whether an item is enabled or disabled. You can
  49. find out whether an item is enabled with [methodname]#isItemEnabled()#.
  50. The [methodname]#setItemEnabled()# identifies the item to be disabled by its
  51. item ID.
  52. [source, java]
  53. ----
  54. // Have an option group with some items
  55. OptionGroup group = new OptionGroup("My Disabled Group");
  56. group.addItems("One", "Two", "Three");
  57. // Disable one item by its item ID
  58. group.setItemEnabled("Two", false);
  59. ----
  60. The item IDs are also used for the captions in this example. The result is shown
  61. in <<figure.components.optiongroup.disabling>>.
  62. [[figure.components.optiongroup.disabling]]
  63. .[classname]#OptionGroup# with a Disabled Item
  64. image::img/optiongroup-disabling.png[width=25%, scaledwidth=50%]
  65. Setting an item as disabled turns on the [literal]#++v-disabled++# style for it.
  66. endif::web[]
  67. [[components.optiongroup.css]]
  68. == CSS Style Rules
  69. [source, css]
  70. ----
  71. .v-select-optiongroup {}
  72. .v-select-option.v-checkbox {}
  73. .v-select-option.v-radiobutton {}
  74. ----
  75. The [literal]#++v-select-optiongroup++# is the overall style for the component.
  76. Each check box will have the [literal]#++v-checkbox++# style, borrowed from the
  77. [classname]#CheckBox# component, and each radio button the
  78. [literal]#++v-radiobutton++# style. Both the radio buttons and check boxes will
  79. also have the [literal]#++v-select-option++# style that allows styling
  80. regardless of the option type. Disabled items have additionally the
  81. [literal]#++v-disabled++# style.
  82. ifdef::web[]
  83. [[components.optiongroup.css.horizontal]]
  84. === Horizontal Layout
  85. The options are normally laid out vertically. You can use horizontal layout by
  86. setting [literal]#++display: inline-block++# for the options. The
  87. [literal]#++nowrap++# setting for the overall element prevents wrapping if there
  88. is not enough horizontal space in the layout, or if the horizontal width is
  89. undefined.
  90. [source, css]
  91. ----
  92. /* Lay the options horizontally */
  93. .v-select-optiongroup-horizontal .v-select-option {
  94. display: inline-block;
  95. }
  96. /* Avoid wrapping if the layout is too tight */
  97. .v-select-optiongroup-horizontal {
  98. white-space: nowrap;
  99. }
  100. /* Some extra spacing is needed */
  101. .v-select-optiongroup-horizontal
  102. .v-select-option.v-radiobutton {
  103. padding-right: 10px;
  104. }
  105. ----
  106. Use of the above rules requires setting a custom [literal]#++horizontal++# style
  107. name for the component. The result is shown in
  108. <<figure.components.optiongroup.horizontal>>.
  109. [[figure.components.optiongroup.horizontal]]
  110. .Horizontal [classname]#OptionGroup#
  111. image::img/optiongroup-horizontal.png[width=35%, scaledwidth=50%]
  112. endif::web[]