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