Search in sources :

Example 16 with FormLayout

use of com.vaadin.flow.component.formlayout.FormLayout in project docs by vaadin.

the class CrudEditorContent method createEditor.

// tag::snippet2[]
private CrudEditor<Person> createEditor() {
    TextField firstName = new TextField("First name");
    TextField lastName = new TextField("Last name");
    EmailField email = new EmailField("Email");
    ComboBox<String> profession = new ComboBox<>("Profession");
    profession.setItems(professions);
    FormLayout form = new FormLayout(firstName, lastName, email, profession);
    form.setColspan(email, 2);
    form.setColspan(profession, 2);
    form.setMaxWidth("480px");
    form.setResponsiveSteps(new FormLayout.ResponsiveStep("0", 1), new FormLayout.ResponsiveStep("30em", 2));
    Binder<Person> binder = new Binder<>(Person.class);
    binder.forField(firstName).asRequired().bind(Person::getFirstName, Person::setFirstName);
    binder.forField(lastName).asRequired().bind(Person::getLastName, Person::setLastName);
    binder.forField(email).asRequired().bind(Person::getEmail, Person::setEmail);
    binder.forField(profession).asRequired().bind(Person::getProfession, Person::setProfession);
    return new BinderCrudEditor<>(binder, form);
}
Also used : FormLayout(com.vaadin.flow.component.formlayout.FormLayout) Binder(com.vaadin.flow.data.binder.Binder) ComboBox(com.vaadin.flow.component.combobox.ComboBox) EmailField(com.vaadin.flow.component.textfield.EmailField) TextField(com.vaadin.flow.component.textfield.TextField) BinderCrudEditor(com.vaadin.flow.component.crud.BinderCrudEditor) Person(com.vaadin.demo.domain.Person)

Example 17 with FormLayout

use of com.vaadin.flow.component.formlayout.FormLayout in project docs by vaadin.

the class CrudSortingFiltering method createEditor.

private CrudEditor<Person> createEditor() {
    TextField firstName = new TextField("First name");
    TextField lastName = new TextField("Last name");
    TextField profession = new TextField("Profession");
    FormLayout form = new FormLayout(firstName, lastName, profession);
    Binder<Person> binder = new Binder<>(Person.class);
    binder.forField(firstName).asRequired().bind(Person::getFirstName, Person::setFirstName);
    binder.forField(lastName).asRequired().bind(Person::getLastName, Person::setLastName);
    binder.forField(profession).asRequired().bind(Person::getProfession, Person::setProfession);
    return new BinderCrudEditor<>(binder, form);
}
Also used : FormLayout(com.vaadin.flow.component.formlayout.FormLayout) Binder(com.vaadin.flow.data.binder.Binder) TextField(com.vaadin.flow.component.textfield.TextField) BinderCrudEditor(com.vaadin.flow.component.crud.BinderCrudEditor) Person(com.vaadin.demo.domain.Person)

Example 18 with FormLayout

use of com.vaadin.flow.component.formlayout.FormLayout in project komunumo-server by komunumo.

the class MembersView method createFeedbackForm.

private Component createFeedbackForm() {
    final var div = new Div();
    div.addClassName("feedback-form");
    div.add(new H2("Your Feedback, suggestion, idea..."));
    final var firstName = new TextField("First name");
    firstName.setMinLength(1);
    firstName.setMaxLength(2_000);
    final var lastName = new TextField("Last name");
    lastName.setMinLength(1);
    lastName.setMaxLength(2_000);
    final var email = new EmailField("Email");
    email.setMinLength(1);
    email.setMaxLength(2_000);
    final var feedback = new TextArea("Feedback");
    feedback.setMinLength(1);
    feedback.setMaxLength(2_000);
    final var submit = new Button("Send");
    submit.addThemeVariants(ButtonVariant.LUMO_PRIMARY);
    submit.setEnabled(false);
    submit.setDisableOnClick(true);
    List.of(firstName, lastName, email, feedback).forEach(field -> {
        field.setRequiredIndicatorVisible(true);
        field.setValueChangeMode(ValueChangeMode.EAGER);
        field.addValueChangeListener(valueChangeEvent -> submit.setEnabled(!firstName.getValue().isBlank() && !lastName.getValue().isBlank() && !email.isInvalid() && !feedback.getValue().isBlank()));
    });
    final var form = new FormLayout();
    form.setResponsiveSteps(new FormLayout.ResponsiveStep("0", 1));
    form.add(firstName, lastName, email, feedback, submit);
    div.add(form);
    submit.addClickListener(buttonClickEvent -> {
        databaseService.receiveFeedback(firstName.getValue(), lastName.getValue(), email.getValue(), feedback.getValue());
        div.replace(form, new Paragraph("We have received your feedback, thank you very much!"));
    });
    firstName.focus();
    return div;
}
Also used : Div(com.vaadin.flow.component.html.Div) FormLayout(com.vaadin.flow.component.formlayout.FormLayout) TextArea(com.vaadin.flow.component.textfield.TextArea) Button(com.vaadin.flow.component.button.Button) EmailField(com.vaadin.flow.component.textfield.EmailField) TextField(com.vaadin.flow.component.textfield.TextField) H2(com.vaadin.flow.component.html.H2) Paragraph(com.vaadin.flow.component.html.Paragraph)

Example 19 with FormLayout

use of com.vaadin.flow.component.formlayout.FormLayout 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 20 with FormLayout

use of com.vaadin.flow.component.formlayout.FormLayout in project linkki by linkki-framework.

the class UIFormLayoutIntegrationTest method testCreation.

@Test
void testCreation() {
    BindingContext bindingContext = new BindingContext();
    FormLayoutPmo pmo = new FormLayoutPmo();
    Component component = VaadinUiCreator.createComponent(pmo, bindingContext);
    assertThat("UiCreator should be able to create a FormLayout", component, is(instanceOf(FormLayout.class)));
    FormLayout layout = (FormLayout) component;
    assertThat("Child component should be correctly created", layout.getChildren().count(), is(1L));
    assertThat("Child component should be correctly created", layout.getChildren().findFirst().get(), is(instanceOf(TextField.class)));
    TextField textField = (TextField) layout.getChildren().findFirst().get();
    pmo.setText("new text");
    bindingContext.modelChanged();
    assertThat("Child components should be correctly bound", textField.getValue(), is("new text"));
}
Also used : FormLayout(com.vaadin.flow.component.formlayout.FormLayout) 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) Test(org.junit.jupiter.api.Test)

Aggregations

FormLayout (com.vaadin.flow.component.formlayout.FormLayout)47 TextField (com.vaadin.flow.component.textfield.TextField)28 Binder (com.vaadin.flow.data.binder.Binder)21 BinderCrudEditor (com.vaadin.flow.component.crud.BinderCrudEditor)15 Person (com.vaadin.demo.domain.Person)12 EmailField (com.vaadin.flow.component.textfield.EmailField)10 Div (com.vaadin.flow.component.html.Div)8 ResponsiveStep (com.vaadin.flow.component.formlayout.FormLayout.ResponsiveStep)6 FormItem (com.vaadin.flow.component.formlayout.FormLayout.FormItem)4 Label (com.vaadin.flow.component.html.Label)4 NumberField (com.vaadin.flow.component.textfield.NumberField)4 TextArea (com.vaadin.flow.component.textfield.TextArea)4 StringLengthValidator (com.vaadin.flow.data.validator.StringLengthValidator)4 FurmsFormLayout (io.imunity.furms.ui.components.FurmsFormLayout)4 Test (org.junit.Test)4 ValueChangeEvent (com.vaadin.flow.component.HasValue.ValueChangeEvent)3 Checkbox (com.vaadin.flow.component.checkbox.Checkbox)3 ComboBox (com.vaadin.flow.component.combobox.ComboBox)3 RichTextEditor (com.vaadin.flow.component.richtexteditor.RichTextEditor)3 EAGER (com.vaadin.flow.data.value.ValueChangeMode.EAGER)3