CheckBoxGroup and RadioButtonGroup

Live Demo

RadioButtonGroup is a single selection component that allows selection from a group of radio buttons. CheckBoxGroup is a multiselection component where items are displayed as check boxes. The common selection component features are described in “Selection Components”.

optiongroup basic

RadioButtonGroup and CheckBoxGroup

Java

  1. // A single-select radio button group
  2. RadioButtonGroup<String> single =
  3. new RadioButtonGroup<>("Single Selection");
  4. single.setItems("Single", "Sola", "Yksi");
  5. // A multi-select check box group
  6. CheckBoxGroup<String> multi =
  7. new CheckBoxGroup<>("Multiple Selection");
  8. multi.setItems("Many", "Muchos", "Monta");

RadioButtonGroup and CheckBoxGroup shows the RadioButtonGroup and CheckBoxGroup.

You can also create check boxes individually using the CheckBox class, as described in “CheckBox”. The advantages of the CheckBoxGroup component are that as it maintains the individual check box objects, you can get an array of the currently selected items easily, and that you can easily change the appearance of a single component and use it with a Binder.

Disabling Items

You can disable individual items in a RadioButtonGroup or a CheckBoxGroup with setItemEnabledProvider(). The user can not select or deselect disabled items in a CheckBoxGroup, but in a RadioButtonGroup the user can change the selection from a disabled to an enabled item. The selections can be changed programmatically regardless of whether an item is enabled or disabled.

Java

  1. // Have a radio button group with some items
  2. RadioButtonGroup<String> group = new RadioButtonGroup<>("My Disabled Group");
  3. group.setItems("One", "Two", "Three");
  4. // Disable one item
  5. group.setItemEnabledProvider(item-> !"Two".equals(item));

optiongroup disabling

RadioButtonGroup with a Disabled Item

Setting an item as disabled turns on the v-disabled style for it.

CSS Style Rules

CSS

  1. .v-select-optiongroup {}
  2. .v-select-option.v-checkbox {}
  3. .v-select-option.v-radiobutton {}

The v-select-optiongroup is the overall style for the component. Each check box will have the v-checkbox style, borrowed from the CheckBox component, and each radio button the v-radiobutton style. Both the radio buttons and check boxes will also have the v-select-option style that allows styling regardless of the option type and additionally v-select-option-selected when the item is selected. Disabled items have additionally the v-disabled style.

Horizontal Layout

The options are normally laid out vertically. You can switch to horizontal layout by using the style name ValoTheme.OPTIONGROUP_HORIZONTAL with addStyleName().