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-optiongroups.asciidoc 3.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. ---
  2. title: CheckBoxGroup and RadioButtonGroup
  3. order: 19
  4. layout: page
  5. ---
  6. [[components.optiongroups]]
  7. = CheckBoxGroup and RadioButtonGroup
  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]#RadioButtonGroup# is a single selection component that allows
  13. selection from a group of radio buttons. [classname]#CheckBoxGroup# is a multiselection
  14. component where items are displayed 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.optiongroups]]
  18. .RadioButtonGroup and CheckBoxGroup
  19. image::img/optiongroup-basic.png[width=45%, scaledwidth=70%]
  20. [source, java]
  21. ----
  22. // A single-select radio button group
  23. RadioButtonGroup<String> single =
  24. new RadioButtonGroup<>("Single Selection");
  25. single.setItems("Single", "Sola", "Yksi");
  26. // A multi-select check box group
  27. CheckBoxGroup<String> multi =
  28. new CheckBoxGroup<>("Multiple Selection");
  29. multi.setItems("Many", "Muchos", "Monta");
  30. ----
  31. <<figure.components.optiongroups>> shows the [classname]#RadioButtonGroup# and
  32. [classname]#CheckBoxGroup#.
  33. You can also create check boxes individually using the [classname]#CheckBox#
  34. class, as described in
  35. <<dummy/../../../framework/components/components-checkbox#components.checkbox,"CheckBox">>.
  36. The advantages of the [classname]#CheckBoxGroup# component are that as it
  37. maintains the individual check box objects, you can get an array of the
  38. currently selected items easily, and that you can easily change the appearance
  39. of a single component and use it with a [classname]#Binder#.
  40. [[components.optiongroups.disabling]]
  41. == Disabling Items
  42. You can disable individual items in a [classname]#RadioButtonGroup# or a [classname]#CheckBoxGroup# with
  43. [methodname]#setItemEnabledProvider()#. The user can not select or deselect disabled
  44. items in a [classname]#CheckBoxGroup#, but in a [classname]#RadioButtonGroup# the user can change the
  45. selection from a disabled to an enabled item. The selections can be changed
  46. programmatically regardless of whether an item is enabled or disabled.
  47. [source, java]
  48. ----
  49. // Have a radio button group with some items
  50. RadioButtonGroup<String> group = new RadioButtonGroup<>("My Disabled Group");
  51. group.setItems("One", "Two", "Three");
  52. // Disable one item
  53. group.setItemEnabledProvider(item-> !"Two".equals(item));
  54. ----
  55. [[figure.components.optiongroups.disabling]]
  56. .[classname]#RadioButtonGroup# with a Disabled Item
  57. image::img/optiongroup-disabling.png[width=25%, scaledwidth=50%]
  58. Setting an item as disabled turns on the [literal]#++v-disabled++# style for it.
  59. [[components.optiongroups.css]]
  60. == CSS Style Rules
  61. [source, css]
  62. ----
  63. .v-select-optiongroup {}
  64. .v-select-option.v-checkbox {}
  65. .v-select-option.v-radiobutton {}
  66. ----
  67. The [literal]#++v-select-optiongroup++# is the overall style for the component.
  68. Each check box will have the [literal]#++v-checkbox++# style, borrowed from the
  69. [classname]#CheckBox# component, and each radio button the
  70. [literal]#++v-radiobutton++# style. Both the radio buttons and check boxes will
  71. also have the [literal]#++v-select-option++# style that allows styling
  72. regardless of the option type. Disabled items have additionally the
  73. [literal]#++v-disabled++# style.
  74. [[components.optiongroups.css.horizontal]]
  75. === Horizontal Layout
  76. The options are normally laid out vertically. You can switch to horizontal layout by using the style name [parameter]#ValoTheme.OPTIONGROUP_HORIZONTAL# with [methodname]#addStyleName()#.