Search in sources :

Example 1 with FormItem

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();
}
Also used : FormItem(com.vaadin.flow.component.formlayout.FormLayout.FormItem) Label(com.vaadin.flow.component.html.Label) Component(com.vaadin.flow.component.Component)

Example 2 with FormItem

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));
}
Also used : Div(com.vaadin.flow.component.html.Div) BaseSection(org.linkki.core.vaadin.component.section.BaseSection) LabelComponentFormItem(org.linkki.core.vaadin.component.base.LabelComponentFormItem) FormItem(com.vaadin.flow.component.formlayout.FormLayout.FormItem) UITextField(org.linkki.core.ui.element.annotation.UITextField) TextField(com.vaadin.flow.component.textfield.TextField) BindingContext(org.linkki.core.binding.BindingContext) Component(com.vaadin.flow.component.Component) HorizontalLayout(com.vaadin.flow.component.orderedlayout.HorizontalLayout) UIHorizontalLayout(org.linkki.core.ui.layout.annotation.UIHorizontalLayout) Test(org.junit.jupiter.api.Test)

Example 3 with FormItem

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);
}
Also used : FormLayout(com.vaadin.flow.component.formlayout.FormLayout) FormItem(com.vaadin.flow.component.formlayout.FormLayout.FormItem) Label(com.vaadin.flow.component.html.Label)

Example 4 with FormItem

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;
    }
}
Also used : FormItem(com.vaadin.flow.component.formlayout.FormLayout.FormItem) Component(com.vaadin.flow.component.Component)

Example 5 with FormItem

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);
}
Also used : FormLayout(com.vaadin.flow.component.formlayout.FormLayout) BinderValidationStatus(com.vaadin.flow.data.binder.BinderValidationStatus) Component(com.vaadin.flow.component.Component) Composite(com.vaadin.flow.component.Composite) EmailValidator(com.vaadin.flow.data.validator.EmailValidator) Binder(com.vaadin.flow.data.binder.Binder) HorizontalLayout(com.vaadin.flow.component.orderedlayout.HorizontalLayout) Div(com.vaadin.flow.component.html.Div) Label(com.vaadin.flow.component.html.Label) NativeButton(com.vaadin.flow.component.html.NativeButton) ResponsiveStep(com.vaadin.flow.component.formlayout.FormLayout.ResponsiveStep) FormItem(com.vaadin.flow.component.formlayout.FormLayout.FormItem) Route(com.vaadin.flow.router.Route) BindingValidationStatus(com.vaadin.flow.data.binder.BindingValidationStatus) SerializablePredicate(com.vaadin.flow.function.SerializablePredicate) TextField(com.vaadin.flow.component.textfield.TextField) ValueChangeMode(com.vaadin.flow.data.value.ValueChangeMode) VerticalLayout(com.vaadin.flow.component.orderedlayout.VerticalLayout) H2(com.vaadin.flow.component.html.H2) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) FormLayout(com.vaadin.flow.component.formlayout.FormLayout) Checkbox(com.vaadin.flow.component.checkbox.Checkbox) StringLengthValidator(com.vaadin.flow.data.validator.StringLengthValidator) DatePicker(com.vaadin.flow.component.datepicker.DatePicker) LocalDate(java.time.LocalDate) Optional(java.util.Optional) Binding(com.vaadin.flow.data.binder.Binder.Binding) NativeButton(com.vaadin.flow.component.html.NativeButton) EmailValidator(com.vaadin.flow.data.validator.EmailValidator) Optional(java.util.Optional) FormItem(com.vaadin.flow.component.formlayout.FormLayout.FormItem) StringLengthValidator(com.vaadin.flow.data.validator.StringLengthValidator) Label(com.vaadin.flow.component.html.Label) BindingValidationStatus(com.vaadin.flow.data.binder.BindingValidationStatus) HorizontalLayout(com.vaadin.flow.component.orderedlayout.HorizontalLayout) Binder(com.vaadin.flow.data.binder.Binder) Checkbox(com.vaadin.flow.component.checkbox.Checkbox) TextField(com.vaadin.flow.component.textfield.TextField) DatePicker(com.vaadin.flow.component.datepicker.DatePicker)

Aggregations

FormItem (com.vaadin.flow.component.formlayout.FormLayout.FormItem)7 Component (com.vaadin.flow.component.Component)4 FormLayout (com.vaadin.flow.component.formlayout.FormLayout)4 Div (com.vaadin.flow.component.html.Div)3 Label (com.vaadin.flow.component.html.Label)3 HorizontalLayout (com.vaadin.flow.component.orderedlayout.HorizontalLayout)2 TextField (com.vaadin.flow.component.textfield.TextField)2 Item (io.bssw.psip.backend.data.Item)2 ScoreItem (io.bssw.psip.ui.components.ScoreItem)2 Composite (com.vaadin.flow.component.Composite)1 Checkbox (com.vaadin.flow.component.checkbox.Checkbox)1 DatePicker (com.vaadin.flow.component.datepicker.DatePicker)1 ResponsiveStep (com.vaadin.flow.component.formlayout.FormLayout.ResponsiveStep)1 Anchor (com.vaadin.flow.component.html.Anchor)1 Emphasis (com.vaadin.flow.component.html.Emphasis)1 H2 (com.vaadin.flow.component.html.H2)1 NativeButton (com.vaadin.flow.component.html.NativeButton)1 Paragraph (com.vaadin.flow.component.html.Paragraph)1 VerticalLayout (com.vaadin.flow.component.orderedlayout.VerticalLayout)1 ProgressBar (com.vaadin.flow.component.progressbar.ProgressBar)1