Search in sources :

Example 6 with EmailField

use of com.vaadin.flow.component.textfield.EmailField 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 7 with EmailField

use of com.vaadin.flow.component.textfield.EmailField in project komunumo-server by komunumo.

the class MemberDialog method createForm.

@Override
public void createForm(@NotNull final FormLayout formLayout, @NotNull final Binder<Member> binder) {
    final var firstName = new TextField("First name");
    final var lastName = new TextField("Last name");
    final var company = new TextField("Company");
    final var email = new EmailField("Email");
    final var active = new Checkbox("Active");
    final var address = new TextField("Address");
    final var zipCode = new TextField("Zip code");
    final var city = new TextField("City");
    final var state = new TextField("State");
    final var country = new TextField("Country");
    final var admin = new Checkbox("Member is Admin");
    final var blocked = new Checkbox("Account Blocked");
    final var blockedReason = new TextField("Reason");
    final var comment = new TextArea("Comment");
    firstName.setRequiredIndicatorVisible(true);
    firstName.setValueChangeMode(EAGER);
    lastName.setRequiredIndicatorVisible(true);
    lastName.setValueChangeMode(EAGER);
    blocked.addValueChangeListener(event -> {
        final var isBlocked = event.getValue();
        blockedReason.setEnabled(isBlocked);
        blockedReason.setRequiredIndicatorVisible(isBlocked);
        if (isBlocked) {
            blockedReason.focus();
        } else {
            blockedReason.setValue("");
        }
        binder.validate();
    });
    blockedReason.setValueChangeMode(EAGER);
    blockedReason.setEnabled(false);
    formLayout.add(firstName, lastName, company, email, active, address, zipCode, city, state, country, admin, blocked, blockedReason, comment);
    binder.forField(firstName).withValidator(new StringLengthValidator("Please enter the first name of the member (max. 255 chars)", 1, 255)).bind(Member::getFirstName, Member::setFirstName);
    binder.forField(lastName).withValidator(new StringLengthValidator("Please enter the last name of the member (max. 255 chars)", 1, 255)).bind(Member::getLastName, Member::setLastName);
    binder.forField(company).bind(Member::getCompany, Member::setCompany);
    binder.forField(email).withValidator(new EmailValidator("Please enter a correct email address or leave this field empty", true)).withValidator(new StringLengthValidator("The email address is too long (max. 255 chars)", 0, 255)).bind(Member::getEmail, Member::setEmail);
    binder.forField(active).bind(Member::getAccountActive, Member::setAccountActive);
    binder.forField(address).withValidator(new StringLengthValidator("The address is too long (max. 255 chars)", 0, 255)).bind(Member::getAddress, Member::setAddress);
    binder.forField(zipCode).withValidator(new StringLengthValidator("The zip code is too long (max. 255 chars)", 0, 255)).bind(Member::getZipCode, Member::setZipCode);
    binder.forField(city).withValidator(new StringLengthValidator("The city is too long (max. 255 chars)", 0, 255)).bind(Member::getCity, Member::setCity);
    binder.forField(state).withValidator(new StringLengthValidator("The state is too long (max. 255 chars)", 0, 255)).bind(Member::getState, Member::setState);
    binder.forField(country).withValidator(new StringLengthValidator("The country is too long (max. 255 chars)", 0, 255)).bind(Member::getCountry, Member::setCountry);
    binder.forField(admin).bind(Member::getAdmin, Member::setAdmin);
    binder.forField(blocked).bind(Member::getAccountBlocked, Member::setAccountBlocked);
    binder.forField(blockedReason).withValidator(value -> !blocked.getValue() || blocked.getValue() && !value.isBlank(), "If you want to block this member, you must enter a reason").withValidator(new StringLengthValidator("The reason is too long (max. 255 chars)", 0, 255)).bind(Member::getAccountBlockedReason, Member::setAccountBlockedReason);
    binder.forField(comment).bind(Member::getComment, Member::setComment);
}
Also used : EmailValidator(com.vaadin.flow.data.validator.EmailValidator) TextArea(com.vaadin.flow.component.textfield.TextArea) Checkbox(com.vaadin.flow.component.checkbox.Checkbox) StringLengthValidator(com.vaadin.flow.data.validator.StringLengthValidator) EmailField(com.vaadin.flow.component.textfield.EmailField) TextField(com.vaadin.flow.component.textfield.TextField) Member(org.komunumo.data.entity.Member)

Example 8 with EmailField

use of com.vaadin.flow.component.textfield.EmailField in project docs by vaadin.

the class CrudColumns method createEditor.

private CrudEditor<Person> createEditor() {
    TextField firstName = new TextField("First name");
    EmailField email = new EmailField("Email");
    TextField profession = new TextField("Profession");
    DatePicker birthday = new DatePicker("Birthday");
    FormLayout form = new FormLayout(firstName, email, profession, birthday);
    Binder<Person> binder = new Binder<>(Person.class);
    binder.forField(firstName).asRequired().bind(Person::getFirstName, Person::setFirstName);
    binder.forField(email).asRequired().bind(Person::getEmail, Person::setEmail);
    binder.forField(profession).asRequired().bind(Person::getProfession, Person::setProfession);
    binder.forField(birthday).asRequired().withConverter(new LocalDateToDateConverter()).bind(Person::getBirthday, Person::setBirthday);
    return new BinderCrudEditor<>(binder, form);
}
Also used : FormLayout(com.vaadin.flow.component.formlayout.FormLayout) Binder(com.vaadin.flow.data.binder.Binder) EmailField(com.vaadin.flow.component.textfield.EmailField) TextField(com.vaadin.flow.component.textfield.TextField) DatePicker(com.vaadin.flow.component.datepicker.DatePicker) BinderCrudEditor(com.vaadin.flow.component.crud.BinderCrudEditor) Person(com.vaadin.demo.domain.Person) LocalDateToDateConverter(com.vaadin.flow.data.converter.LocalDateToDateConverter)

Example 9 with EmailField

use of com.vaadin.flow.component.textfield.EmailField in project docs by vaadin.

the class CrudEditorBottom method createEditor.

private CrudEditor<Person> createEditor() {
    TextField firstName = new TextField("First name");
    TextField lastName = new TextField("Last name");
    EmailField email = new EmailField("Email");
    TextField profession = new TextField("Profession");
    FormLayout form = new FormLayout(firstName, lastName, email, 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(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) 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 10 with EmailField

use of com.vaadin.flow.component.textfield.EmailField in project docs by vaadin.

the class CrudGridReplacement method createEditor.

private CrudEditor<Person> createEditor() {
    TextField firstName = new TextField("First name");
    TextField lastName = new TextField("Last name");
    EmailField email = new EmailField("Email");
    TextField profession = new TextField("Profession");
    FormLayout form = new FormLayout(firstName, lastName, email, 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(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) 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)

Aggregations

EmailField (com.vaadin.flow.component.textfield.EmailField)17 TextField (com.vaadin.flow.component.textfield.TextField)14 FormLayout (com.vaadin.flow.component.formlayout.FormLayout)10 Person (com.vaadin.demo.domain.Person)9 BinderCrudEditor (com.vaadin.flow.component.crud.BinderCrudEditor)9 Binder (com.vaadin.flow.data.binder.Binder)9 TextArea (com.vaadin.flow.component.textfield.TextArea)3 Test (org.junit.Test)3 Button (com.vaadin.flow.component.button.Button)2 Div (com.vaadin.flow.component.html.Div)2 PasswordField (com.vaadin.flow.component.textfield.PasswordField)2 EmailValidator (com.vaadin.flow.data.validator.EmailValidator)2 StringLengthValidator (com.vaadin.flow.data.validator.StringLengthValidator)2 AuthService (com.example.application.data.services.AuthService)1 MainLayout (com.example.application.views.MainLayout)1 Component (com.vaadin.flow.component.Component)1 Composite (com.vaadin.flow.component.Composite)1 HasLabel (com.vaadin.flow.component.HasLabel)1 Checkbox (com.vaadin.flow.component.checkbox.Checkbox)1 ComboBox (com.vaadin.flow.component.combobox.ComboBox)1