use of com.vaadin.flow.component.checkbox.CheckboxGroup in project flow-components by vaadin.
the class CheckboxGroupDemoPage method addDisabledItems.
private void addDisabledItems() {
Div valueInfo = new Div();
// provider
CheckboxGroup<String> group = new CheckboxGroup<>();
group.setItems("foo", "bar", "baz");
group.setItemEnabledProvider(item -> !"bar".equals(item));
group.addValueChangeListener(event -> valueInfo.setText(toString(group.getValue())));
group.setId("checkbox-group-disabled-items");
valueInfo.setId("checkbox-group-disabled-items-info");
addCard("Checkbox group with item enabled provider", group, valueInfo);
}
use of com.vaadin.flow.component.checkbox.CheckboxGroup in project flow-components by vaadin.
the class CheckboxGroupDemoPage method addBasicFeatures.
private void addBasicFeatures() {
Div message = new Div();
CheckboxGroup<String> group = new CheckboxGroup<>();
group.setItems("foo", "bar", "baz");
group.addValueChangeListener(event -> message.setText(String.format("Checkbox group value changed from '%s' to '%s'", toString(event.getOldValue()), toString(event.getValue()))));
group.setId("checkbox-group-with-value-change-listener");
message.setId("checkbox-group-value");
addCard("Basic checkbox group", group, message);
}
use of com.vaadin.flow.component.checkbox.CheckboxGroup in project flow-components by vaadin.
the class CheckboxGroupDemoPage method addHelperCheckboxGroup.
private void addHelperCheckboxGroup() {
// component
CheckboxGroup<String> groupHelperText = new CheckboxGroup<>();
groupHelperText.setItems("foo", "bar", "baz");
groupHelperText.setHelperText("Helper text");
NativeButton clearHelper = new NativeButton("Clear helper text", e -> {
groupHelperText.setHelperText(null);
});
CheckboxGroup<String> groupHelperComponent = new CheckboxGroup<>();
groupHelperComponent.setItems("foo", "bar", "baz");
Span span = new Span("Helper text");
span.setId("helper-component");
groupHelperComponent.setHelperComponent(span);
NativeButton clearHelperComponent = new NativeButton("Clear helper text", e -> {
groupHelperComponent.setHelperComponent(null);
});
groupHelperText.setId("checkbox-helper-text");
groupHelperComponent.setId("checkbox-helper-component");
span.setId("component-helper");
clearHelper.setId("button-clear-helper");
clearHelperComponent.setId("button-clear-component");
addCard("CheckboxGroup with helper text and helper component", groupHelperText, clearHelper, groupHelperComponent, clearHelperComponent);
}
use of com.vaadin.flow.component.checkbox.CheckboxGroup in project flow-components by vaadin.
the class CheckboxGroupTest method disableParent_detachParent_notThrowing.
// https://github.com/vaadin/vaadin-checkbox-flow/issues/81
@Test
public void disableParent_detachParent_notThrowing() {
CheckboxGroup<String> checkboxGroup = new CheckboxGroup<>();
checkboxGroup.setItems("foo", "bar");
Div parent = new Div(checkboxGroup);
UI ui = new UI();
ui.add(parent);
parent.setEnabled(false);
ui.remove(parent);
}
use of com.vaadin.flow.component.checkbox.CheckboxGroup in project flow-components by vaadin.
the class CheckboxGroupTest method elementHasValue_wrapIntoField_propertyIsNotSetToInitialValue.
@SuppressWarnings("rawtypes")
@Test
public void elementHasValue_wrapIntoField_propertyIsNotSetToInitialValue() {
Element element = new Element("vaadin-checkbox-group");
JsonArray array = Json.createArray();
array.set(0, "foo");
element.setPropertyJson("value", array);
UI ui = new UI();
UI.setCurrent(ui);
VaadinSession session = Mockito.mock(VaadinSession.class);
ui.getInternals().setSession(session);
VaadinService service = Mockito.mock(VaadinService.class);
Mockito.when(session.getService()).thenReturn(service);
Instantiator instantiator = Mockito.mock(Instantiator.class);
Mockito.when(service.getInstantiator()).thenReturn(instantiator);
Mockito.when(instantiator.createComponent(CheckboxGroup.class)).thenAnswer(invocation -> new CheckboxGroup());
CheckboxGroup field = Component.from(element, CheckboxGroup.class);
JsonArray propertyValue = (JsonArray) field.getElement().getPropertyRaw("value");
Assert.assertEquals(1, propertyValue.length());
Assert.assertEquals("foo", propertyValue.getString(0));
}
Aggregations