Search in sources :

Example 1 with CrudEditor

use of com.vaadin.flow.component.crud.CrudEditor 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)

Aggregations

BinderCrudEditor (com.vaadin.flow.component.crud.BinderCrudEditor)1 CrudEditor (com.vaadin.flow.component.crud.CrudEditor)1 CrudI18n (com.vaadin.flow.component.crud.CrudI18n)1 FormLayout (com.vaadin.flow.component.formlayout.FormLayout)1 TextField (com.vaadin.flow.component.textfield.TextField)1 Binder (com.vaadin.flow.data.binder.Binder)1