use of com.vaadin.flow.component.formlayout.FormLayout.FormItem in project linkki by linkki-framework.
the class TestUiUtil method getLabelOfComponentAt.
public static String getLabelOfComponentAt(Div layout, int row) {
List<Component> children = layout.getChildren().collect(Collectors.toList());
FormItem formItem = (FormItem) children.get(row);
return ((Label) formItem.getChildren().collect(Collectors.toList()).get(1)).getText();
}
use of com.vaadin.flow.component.formlayout.FormLayout.FormItem in project linkki by linkki-framework.
the class UINestedComponentIntegrationTest method testCreateNestedComponent.
@Test
public void testCreateNestedComponent() {
BaseSection component = (BaseSection) VaadinUiCreator.createComponent(new NestedComponentPmo(), new BindingContext());
List<FormItem> childComponents = component.getContentWrapper().getChildren().map(FormItem.class::cast).collect(Collectors.toList());
assertThat(childComponents.stream().map(i -> getChild(i, 0)).collect(Collectors.toList()), contains(instanceOf(TextField.class), instanceOf(Div.class)));
FormItem nestedComponentFormItem = childComponents.get(1);
assertThat(getChild(nestedComponentFormItem, 1).getElement().getText(), is("Name/Vorname"));
Div nestedComponentWrapper = (Div) getChild(nestedComponentFormItem, 0);
assertThat(nestedComponentWrapper.getWidth(), is("100px"));
assertThat(nestedComponentWrapper.getClassName(), is("style1 style2"));
Component nestedComponent = getChild(nestedComponentWrapper, 0);
assertThat(nestedComponent, instanceOf(HorizontalLayout.class));
assertThat(((HorizontalLayout) nestedComponent).getWidth(), is("100px"));
assertThat(getChild(nestedComponent, 0), instanceOf(TextField.class));
}
use of com.vaadin.flow.component.formlayout.FormLayout.FormItem in project linkki by linkki-framework.
the class OverflowIssues method requiredIndicatorWithEmptyLabel.
private void requiredIndicatorWithEmptyLabel() {
add(new Label("This layout must not have a scrollbar:"));
FormLayout formLayout = new FormLayout();
FormItem formItem = formLayout.addFormItem(new Label("Ich bin ein Label ohne Label"), "");
formItem.getStyle().set("overflow", "auto");
add(formLayout);
}
use of com.vaadin.flow.component.formlayout.FormLayout.FormItem in project linkki by linkki-framework.
the class TestUiUtil method getComponentAtIndex.
public static Component getComponentAtIndex(int index, Component component) {
List<Component> children = component.getChildren().collect(Collectors.toList());
Component componentAtIndex = children.get(index);
if (componentAtIndex instanceof FormItem) {
FormItem formItem = (FormItem) componentAtIndex;
return formItem.getChildren().collect(Collectors.toList()).get(0);
} else {
return componentAtIndex;
}
}
use of com.vaadin.flow.component.formlayout.FormLayout.FormItem in project flow-components by vaadin.
the class FormLayoutView method createFormLayoutWithBinder.
private void createFormLayoutWithBinder() {
FormLayout layoutWithBinder = new FormLayout();
Binder<Contact> binder = new Binder<>();
// The object that will be edited
Contact contactBeingEdited = new Contact();
// Create the fields
TextField firstName = new TextField();
firstName.setValueChangeMode(ValueChangeMode.EAGER);
TextField lastName = new TextField();
lastName.setValueChangeMode(ValueChangeMode.EAGER);
TextField phone = new TextField();
phone.setValueChangeMode(ValueChangeMode.EAGER);
TextField email = new TextField();
email.setValueChangeMode(ValueChangeMode.EAGER);
DatePicker birthDate = new DatePicker();
Checkbox doNotCall = new Checkbox("Do not call");
Label infoLabel = new Label();
NativeButton save = new NativeButton("Save");
NativeButton reset = new NativeButton("Reset");
layoutWithBinder.addFormItem(firstName, "First name");
layoutWithBinder.addFormItem(lastName, "Last name");
layoutWithBinder.addFormItem(birthDate, "Birthdate");
layoutWithBinder.addFormItem(email, "E-mail");
FormItem phoneItem = layoutWithBinder.addFormItem(phone, "Phone");
phoneItem.add(doNotCall);
// Button bar
HorizontalLayout actions = new HorizontalLayout();
actions.add(save, reset);
save.getStyle().set("marginRight", "10px");
SerializablePredicate<String> phoneOrEmailPredicate = value -> !phone.getValue().trim().isEmpty() || !email.getValue().trim().isEmpty();
// E-mail and phone have specific validators
Binding<Contact, String> emailBinding = binder.forField(email).withValidator(phoneOrEmailPredicate, "Both phone and email cannot be empty").withValidator(new EmailValidator("Incorrect email address")).bind(Contact::getEmail, Contact::setEmail);
Binding<Contact, String> phoneBinding = binder.forField(phone).withValidator(phoneOrEmailPredicate, "Both phone and email cannot be empty").bind(Contact::getPhone, Contact::setPhone);
// Trigger cross-field validation when the other field is changed
email.addValueChangeListener(event -> phoneBinding.validate());
phone.addValueChangeListener(event -> emailBinding.validate());
// First name and last name are required fields
firstName.setRequiredIndicatorVisible(true);
lastName.setRequiredIndicatorVisible(true);
binder.forField(firstName).withValidator(new StringLengthValidator("Please add the first name", 1, null)).bind(Contact::getFirstName, Contact::setFirstName);
binder.forField(lastName).withValidator(new StringLengthValidator("Please add the last name", 1, null)).bind(Contact::getLastName, Contact::setLastName);
// Birthdate and doNotCall don't need any special validators
binder.bind(doNotCall, Contact::isDoNotCall, Contact::setDoNotCall);
binder.bind(birthDate, Contact::getBirthDate, Contact::setBirthDate);
// Click listeners for the buttons
save.addClickListener(event -> {
if (binder.writeBeanIfValid(contactBeingEdited)) {
infoLabel.setText("Saved bean values: " + contactBeingEdited);
} else {
BinderValidationStatus<Contact> validate = binder.validate();
String errorText = validate.getFieldValidationStatuses().stream().filter(BindingValidationStatus::isError).map(BindingValidationStatus::getMessage).map(Optional::get).distinct().collect(Collectors.joining(", "));
infoLabel.setText("There are errors: " + errorText);
}
});
reset.addClickListener(event -> {
// clear fields by setting null
binder.readBean(null);
infoLabel.setText("");
doNotCall.setValue(false);
});
infoLabel.setId("binder-info");
firstName.setId("binder-first-name");
lastName.setId("binder-last-name");
phone.setId("binder-phone");
email.setId("binder-email");
birthDate.setId("binder-birth-date");
doNotCall.setId("binder-do-not-call");
save.setId("binder-save");
reset.setId("binder-reset");
addCard("A form layout with fields using Binder", layoutWithBinder, actions, infoLabel);
}
Aggregations