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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations