use of com.vaadin.flow.component.checkbox.CheckboxGroup in project flow-components by vaadin.
the class CheckboxGroupTest method selectDisabledItem_noRedundantEvent.
@Test
public void selectDisabledItem_noRedundantEvent() {
CheckboxGroup<String> group = new CheckboxGroup<>();
group.setItems("enabled", "disabled");
group.setItemEnabledProvider("enabled"::equals);
List<HasValue.ValueChangeEvent<Set<String>>> events = new ArrayList<>();
group.addValueChangeListener(events::add);
List<String> keys = group.getChildren().map(Component::getElement).map(element -> element.getProperty("value")).collect(Collectors.toList());
String enabledKey = keys.get(0);
String disabledKey = keys.get(1);
JsonArray array = Json.createArray();
array.set(0, disabledKey);
group.getElement().setPropertyJson("value", array);
Assert.assertThat(group.getValue(), IsEmptyCollection.empty());
Assert.assertTrue(events.isEmpty());
array = Json.createArray();
array.set(0, enabledKey);
group.getElement().setPropertyJson("value", array);
Assert.assertEquals(Collections.singleton("enabled"), group.getValue());
Assert.assertEquals(1, events.size());
ValueChangeEvent<Set<String>> event = events.get(0);
Assert.assertThat(event.getOldValue(), IsEmptyCollection.empty());
Assert.assertEquals(Collections.singleton("enabled"), event.getValue());
}
use of com.vaadin.flow.component.checkbox.CheckboxGroup in project flow-components by vaadin.
the class CheckboxGroupDemoPage method addComponentWithThemeVariant.
private void addComponentWithThemeVariant() {
CheckboxGroup<String> group = new CheckboxGroup<>();
group.setItems("foo", "bar", "baz");
group.setId("checkbox-group-theme-variants");
group.addThemeVariants(CheckboxGroupVariant.LUMO_VERTICAL);
Button removeVariantButton = new Button("Remove theme variant", e -> {
group.removeThemeVariants(CheckboxGroupVariant.LUMO_VERTICAL);
});
removeVariantButton.setId("remove-theme-variant-button");
addCard("Button theme variants", group, removeVariantButton);
}
use of com.vaadin.flow.component.checkbox.CheckboxGroup in project flow-components by vaadin.
the class CheckboxGroupDemoPage method addItemLabelGenerator.
private void addItemLabelGenerator() {
Div message = new Div();
CheckboxGroup<Person> group = new CheckboxGroup<>();
group.setItems(new Person("Joe"), new Person("John"), new Person("Bill"));
group.setItemLabelGenerator(Person::getName);
group.addValueChangeListener(event -> message.setText(String.format("Checkbox group value changed from '%s' to '%s'", getNames(event.getOldValue()), getNames(event.getValue()))));
group.setId("checkbox-group-with-item-generator");
message.setId("checkbox-group-gen-value");
addCard("Checkbox group with label generator", group, message);
}
use of com.vaadin.flow.component.checkbox.CheckboxGroup in project flow-components by vaadin.
the class CheckboxGroupDemoPage method addComponentWithLabelAndErrorMessage.
private void addComponentWithLabelAndErrorMessage() {
CheckboxGroup<String> group = new CheckboxGroup<>();
group.setItems("foo", "bar", "baz");
group.setLabel("Group label");
group.setErrorMessage("Field has been set to invalid from server side");
NativeButton button = new NativeButton("Switch validity state", event -> group.setInvalid(!group.isInvalid()));
group.setId("group-with-label-and-error-message");
button.setId("group-with-label-button");
addCard("Group with label and error message", group, button);
}
use of com.vaadin.flow.component.checkbox.CheckboxGroup in project flow-components by vaadin.
the class CheckboxGroupDemoPage method addReadOnlyGroup.
private void addReadOnlyGroup() {
Div valueInfo = new Div();
CheckboxGroup<String> group = new CheckboxGroup<>();
group.setItems("foo", "bar", "baz");
group.setReadOnly(true);
NativeButton button = new NativeButton("Switch read-only state", event -> group.setReadOnly(!group.isReadOnly()));
group.addValueChangeListener(event -> valueInfo.setText(toString(group.getValue())));
group.setId("checkbox-group-read-only");
valueInfo.setId("selected-value-info");
button.setId("switch-read-only");
addCard("Read-only checkbox group", group, button, valueInfo);
}
Aggregations