Search in sources :

Example 6 with FormLayout

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

the class Helper method createPersonEditor.

static CrudEditor<Person> createPersonEditor() {
    TextField firstName = new TextField("First name");
    firstName.getElement().setAttribute("editor-role", "first-name");
    TextField lastName = new TextField("Last name");
    lastName.getElement().setAttribute("editor-role", "last-name");
    FormLayout form = new FormLayout(firstName, lastName);
    Binder<Person> binder = new Binder<>(Person.class);
    binder.forField(firstName).asRequired().bind(Person::getFirstName, Person::setFirstName);
    binder.forField(lastName).withValidator(value -> value != null && value.startsWith("O"), "Only last names starting with 'O' allowed").bind(Person::getLastName, Person::setLastName);
    return new BinderCrudEditor<>(binder, form);
}
Also used : FormLayout(com.vaadin.flow.component.formlayout.FormLayout) FormLayout(com.vaadin.flow.component.formlayout.FormLayout) BinderCrudEditor(com.vaadin.flow.component.crud.BinderCrudEditor) CrudI18n(com.vaadin.flow.component.crud.CrudI18n) Binder(com.vaadin.flow.data.binder.Binder) TextField(com.vaadin.flow.component.textfield.TextField) CrudEditor(com.vaadin.flow.component.crud.CrudEditor) Binder(com.vaadin.flow.data.binder.Binder) TextField(com.vaadin.flow.component.textfield.TextField) BinderCrudEditor(com.vaadin.flow.component.crud.BinderCrudEditor)

Example 7 with FormLayout

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

the class FormLayoutView method createResponsiveLayout.

private void createResponsiveLayout() {
    FormLayout nameLayout = new FormLayout();
    TextField titleField = new TextField();
    titleField.setLabel("Title");
    titleField.setPlaceholder("Sir");
    TextField firstNameField = new TextField();
    firstNameField.setLabel("First name");
    firstNameField.setPlaceholder("John");
    TextField lastNameField = new TextField();
    lastNameField.setLabel("Last name");
    lastNameField.setPlaceholder("Doe");
    nameLayout.add(titleField, firstNameField, lastNameField);
    // Default number of columns in a FormLayout is 2. By setting the
    // responsive steps we specify different numbers for columns with
    // breakpoints at “40em” “32em” and “25em”. Now by changing the size of
    // the browser horizontally, you can notice that the number of the
    // columns in the FormLayout changes.
    nameLayout.setResponsiveSteps(new ResponsiveStep("1px", 1), new ResponsiveStep("600px", 2), new ResponsiveStep("700px", 3));
    addCard("A form layout with custom responsive layouting", nameLayout);
}
Also used : FormLayout(com.vaadin.flow.component.formlayout.FormLayout) TextField(com.vaadin.flow.component.textfield.TextField) ResponsiveStep(com.vaadin.flow.component.formlayout.FormLayout.ResponsiveStep)

Example 8 with FormLayout

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

the class CitizenManagementView method createEditor.

/**
 * Create the CRUD Editor
 * @return the CrudEditor
 */
private CrudEditor<Person> createEditor() {
    TextField firstName = new TextField("First name");
    TextField lastName = new TextField("Last name");
    NumberField money = new NumberField("Money");
    money.setReadOnly(true);
    Double randomMoneyAmount = rand.nextDouble(100000 + 1 - 10000) + 10000;
    money.setValue(randomMoneyAmount);
    FormLayout form = new FormLayout(firstName, lastName, money);
    form.setColspan(money, 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(money).asRequired().bind(Person::getMoney, Person::setMoney).setReadOnly(true);
    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.dala.data.person.Person) NumberField(com.vaadin.flow.component.textfield.NumberField)

Example 9 with FormLayout

use of com.vaadin.flow.component.formlayout.FormLayout in project furms by unity-idm.

the class ProjectAllocationDashboardFormView method addForm.

private void addForm(DefaultNameField nameField) {
    final FormLayout formLayout = new FurmsFormLayout();
    final Label availableAmountLabel = new Label();
    formLayout.addFormItem(nameField, getTranslation("view.community-admin.project-allocation.form.field.name"));
    formLayout.addFormItem(projectsField(), getTranslation("view.community-admin.project-allocation.form.field.projects"));
    formLayout.addFormItem(resourceTypeField(), getTranslation("view.community-admin.project-allocation.form.field.resource_type"));
    formLayout.addFormItem(communityAllocation(availableAmountLabel), getTranslation("view.community-admin.project-allocation.form.field.community_allocation"));
    formLayout.addFormItem(amountField(), getTranslation("view.fenix-admin.resource-credits-allocation.form.field.amount"));
    formLayout.addFormItem(availableAmountLabel, "");
    getContent().add(formLayout);
}
Also used : FurmsFormLayout(io.imunity.furms.ui.components.FurmsFormLayout) FormLayout(com.vaadin.flow.component.formlayout.FormLayout) FurmsFormLayout(io.imunity.furms.ui.components.FurmsFormLayout) Label(com.vaadin.flow.component.html.Label)

Example 10 with FormLayout

use of com.vaadin.flow.component.formlayout.FormLayout in project furms by unity-idm.

the class SitesAddView method addForm.

private void addForm() {
    FormLayout formLayout = new FurmsFormLayout();
    formLayout.setSizeFull();
    SiteCreationParam formData = new SiteCreationParam();
    Binder<SiteCreationParam> binder = new Binder<>(SiteCreationParam.class);
    binder.setBean(formData);
    name.setPlaceholder(getTranslation("view.sites.add.form.name.placeholder"));
    name.setRequiredIndicatorVisible(true);
    name.setValueChangeMode(EAGER);
    name.setMaxLength(NAME_MAX_LENGTH);
    Button cancel = new Button(getTranslation("view.sites.add.form.button.cancel"), e -> doCancelAction());
    cancel.addThemeVariants(LUMO_TERTIARY);
    Button save = new Button(getTranslation("view.sites.add.form.button.save"), e -> doSaveAction(formData, binder));
    save.addThemeVariants(LUMO_PRIMARY);
    save.addClickShortcut(Key.ENTER);
    FormButtons buttons = new FormButtons(cancel, save);
    binder.addStatusChangeListener(status -> save.setEnabled(!isBlank(name.getValue()) && !status.hasValidationErrors()));
    binder.forField(name).withValidator(getNotEmptyStringValidator(), getTranslation("view.sites.form.error.validation.field.name.required")).withValidator(siteService::isNamePresent, getTranslation("view.sites.form.error.validation.field.name.unique")).bind(SiteCreationParam::getName, SiteCreationParam::setName);
    formLayout.addFormItem(name, getTranslation("view.sites.add.form.name"));
    getContent().add(formLayout, buttons);
}
Also used : FurmsFormLayout(io.imunity.furms.ui.components.FurmsFormLayout) FormLayout(com.vaadin.flow.component.formlayout.FormLayout) Binder(com.vaadin.flow.data.binder.Binder) FurmsFormLayout(io.imunity.furms.ui.components.FurmsFormLayout) Button(com.vaadin.flow.component.button.Button) FormButtons(io.imunity.furms.ui.components.FormButtons)

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