Search in sources :

Example 41 with ComboBox

use of com.vaadin.flow.component.combobox.ComboBox in project flow-components by vaadin.

the class ComboBoxView method customValues.

private void customValues() {
    Div message = createMessageDiv("custom-value-message");
    ComboBox<String> comboBox = new ComboBox<>("Fruit");
    comboBox.setItems("Apple", "Orange", "Banana");
    /**
     * Allow users to enter a value which doesn't exist in the data set, and
     * set it as the value of the ComboBox.
     */
    comboBox.addCustomValueSetListener(event -> comboBox.setValue(event.getDetail()));
    comboBox.addValueChangeListener(event -> {
        if (event.getValue() == null) {
            message.setText("No fruit selected");
        } else {
            message.setText("Selected value: " + event.getValue());
        }
    });
    comboBox.setId("custom-value-box");
    addCard("Allow custom values", comboBox, message);
}
Also used : Div(com.vaadin.flow.component.html.Div) ComboBox(com.vaadin.flow.component.combobox.ComboBox)

Example 42 with ComboBox

use of com.vaadin.flow.component.combobox.ComboBox in project flow-components by vaadin.

the class ComboBoxView method pagedRepository.

private void pagedRepository() {
    ComboBox<Person> comboBox = new ComboBox<>();
    PersonService service = new PersonService();
    /*
         * For those backend repositories which use paged data fetching, it is
         * possible to get the page number and page size from Query API.
         */
    comboBox.setItems(query -> service.fetchPage(query.getFilter().orElse(null), query.getPage(), query.getPageSize()));
    comboBox.setId("paged-box");
    addCard("Lazy Loading", "Lazy Loading from Paged Repository", comboBox);
}
Also used : ComboBox(com.vaadin.flow.component.combobox.ComboBox) PersonService(com.vaadin.flow.component.combobox.test.service.PersonService) Person(com.vaadin.flow.component.combobox.test.entity.Person)

Example 43 with ComboBox

use of com.vaadin.flow.component.combobox.ComboBox in project flow-components by vaadin.

the class ComboBoxView method configurationForRequired.

private void configurationForRequired() {
    ComboBox<String> requiredComboBox = new ComboBox<>();
    requiredComboBox.setItems("Option one", "Option two", "Option three");
    requiredComboBox.setLabel("Required");
    requiredComboBox.setPlaceholder("Select an option");
    requiredComboBox.setRequired(true);
    requiredComboBox.setClearButtonVisible(true);
    FlexLayout layout = new FlexLayout(requiredComboBox);
    layout.getStyle().set("flex-wrap", "wrap");
    addCard("Validation", "Required", layout);
}
Also used : FlexLayout(com.vaadin.flow.component.orderedlayout.FlexLayout) ComboBox(com.vaadin.flow.component.combobox.ComboBox)

Example 44 with ComboBox

use of com.vaadin.flow.component.combobox.ComboBox in project flow-components by vaadin.

the class ComboBoxView method basicDemo.

private void basicDemo() {
    Div div = new Div();
    ComboBox<String> labelComboBox = new ComboBox<>();
    labelComboBox.setItems("Option one", "Option two");
    labelComboBox.setLabel("Label");
    ComboBox<String> placeHolderComboBox = new ComboBox<>();
    placeHolderComboBox.setItems("Option one", "Option two");
    placeHolderComboBox.setPlaceholder("Placeholder");
    ComboBox<String> valueComboBox = new ComboBox<>();
    valueComboBox.setItems("Value", "Option one", "Option two");
    valueComboBox.setValue("Value");
    labelComboBox.getStyle().set("margin-right", "5px");
    placeHolderComboBox.getStyle().set("margin-right", "5px");
    div.add(labelComboBox, placeHolderComboBox, valueComboBox);
    addCard("Basic usage", div);
}
Also used : Div(com.vaadin.flow.component.html.Div) ComboBox(com.vaadin.flow.component.combobox.ComboBox)

Example 45 with ComboBox

use of com.vaadin.flow.component.combobox.ComboBox in project flow-components by vaadin.

the class ComboBoxView method lazyLoading.

private void lazyLoading() {
    ComboBox<Person> comboBox = new ComboBox<>();
    PersonService service = new PersonService(500);
    /*
         * When provided a callback, the combo box doesn't load all items from
         * backend to server memory right away. It will request only the data
         * that is shown in its current view "window". The data is provided
         * based on string filter, offset and limit.
         *
         * When the user scrolls to the end, combo box will automatically extend
         * and fetch more items until the backend runs out of items.
         */
    comboBox.setItems(query -> service.fetch(query.getFilter().orElse(null), query.getOffset(), query.getLimit()));
    comboBox.setId("fetch-callback");
    addCard("Lazy Loading", "Lazy Loading with Callback", comboBox);
}
Also used : ComboBox(com.vaadin.flow.component.combobox.ComboBox) PersonService(com.vaadin.flow.component.combobox.test.service.PersonService) Person(com.vaadin.flow.component.combobox.test.entity.Person)

Aggregations

ComboBox (com.vaadin.flow.component.combobox.ComboBox)69 Div (com.vaadin.flow.component.html.Div)35 Span (com.vaadin.flow.component.html.Span)21 NativeButton (com.vaadin.flow.component.html.NativeButton)20 Route (com.vaadin.flow.router.Route)18 List (java.util.List)16 H2 (com.vaadin.flow.component.html.H2)14 Collectors (java.util.stream.Collectors)14 Label (com.vaadin.flow.component.html.Label)12 ComponentRenderer (com.vaadin.flow.data.renderer.ComponentRenderer)12 Stream (java.util.stream.Stream)12 Component (com.vaadin.flow.component.Component)10 VerticalLayout (com.vaadin.flow.component.orderedlayout.VerticalLayout)10 ArrayList (java.util.ArrayList)10 Button (com.vaadin.flow.component.button.Button)9 Person (com.vaadin.flow.component.combobox.test.entity.Person)9 PersonService (com.vaadin.flow.component.combobox.test.service.PersonService)9 IntStream (java.util.stream.IntStream)9 ItemFilter (com.vaadin.flow.component.combobox.ComboBox.ItemFilter)8 Paragraph (com.vaadin.flow.component.html.Paragraph)8