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