Search in sources :

Example 1 with CheckboxGroup

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);
}
Also used : Div(com.vaadin.flow.component.html.Div) CheckboxGroup(com.vaadin.flow.component.checkbox.CheckboxGroup)

Example 2 with CheckboxGroup

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);
}
Also used : Div(com.vaadin.flow.component.html.Div) CheckboxGroup(com.vaadin.flow.component.checkbox.CheckboxGroup)

Example 3 with CheckboxGroup

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);
}
Also used : NativeButton(com.vaadin.flow.component.html.NativeButton) CheckboxGroup(com.vaadin.flow.component.checkbox.CheckboxGroup) Span(com.vaadin.flow.component.html.Span)

Example 4 with CheckboxGroup

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);
}
Also used : Div(com.vaadin.flow.component.html.Div) UI(com.vaadin.flow.component.UI) CheckboxGroup(com.vaadin.flow.component.checkbox.CheckboxGroup) Test(org.junit.Test)

Example 5 with CheckboxGroup

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));
}
Also used : JsonArray(elemental.json.JsonArray) UI(com.vaadin.flow.component.UI) VaadinSession(com.vaadin.flow.server.VaadinSession) Element(com.vaadin.flow.dom.Element) CheckboxGroup(com.vaadin.flow.component.checkbox.CheckboxGroup) VaadinService(com.vaadin.flow.server.VaadinService) Instantiator(com.vaadin.flow.di.Instantiator) Test(org.junit.Test)

Aggregations

CheckboxGroup (com.vaadin.flow.component.checkbox.CheckboxGroup)10 Div (com.vaadin.flow.component.html.Div)6 NativeButton (com.vaadin.flow.component.html.NativeButton)4 UI (com.vaadin.flow.component.UI)3 Test (org.junit.Test)3 Instantiator (com.vaadin.flow.di.Instantiator)2 Element (com.vaadin.flow.dom.Element)2 VaadinService (com.vaadin.flow.server.VaadinService)2 VaadinSession (com.vaadin.flow.server.VaadinSession)2 JsonArray (elemental.json.JsonArray)2 Component (com.vaadin.flow.component.Component)1 HasValue (com.vaadin.flow.component.HasValue)1 ValueChangeEvent (com.vaadin.flow.component.HasValue.ValueChangeEvent)1 Button (com.vaadin.flow.component.button.Button)1 Checkbox (com.vaadin.flow.component.checkbox.Checkbox)1 CheckboxGroupListDataView (com.vaadin.flow.component.checkbox.dataview.CheckboxGroupListDataView)1 Span (com.vaadin.flow.component.html.Span)1 DataProvider (com.vaadin.flow.data.provider.DataProvider)1 ListDataProvider (com.vaadin.flow.data.provider.ListDataProvider)1 MultiSelectionEvent (com.vaadin.flow.data.selection.MultiSelectionEvent)1