use of com.vaadin.flow.component.textfield.EmailField in project flow-components by vaadin.
the class ValueChangeModePage method initView.
private void initView() {
message = new Div();
message.setId("message");
add(message);
Stream.of(new TextField(), new TextArea(), new PasswordField(), new NumberField(), new EmailField(), new IntegerField(), new BigDecimalField()).forEach(this::setupTestComponent);
}
use of com.vaadin.flow.component.textfield.EmailField in project docs by vaadin.
the class CrudBasic 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 CrudEditorAside 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 CrudEditorContent method createEditor.
// tag::snippet2[]
private CrudEditor<Person> createEditor() {
TextField firstName = new TextField("First name");
TextField lastName = new TextField("Last name");
EmailField email = new EmailField("Email");
ComboBox<String> profession = new ComboBox<>("Profession");
profession.setItems(professions);
FormLayout form = new FormLayout(firstName, lastName, email, profession);
form.setColspan(email, 2);
form.setColspan(profession, 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(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 komunumo-server by komunumo.
the class SpeakerDialog method createForm.
@Override
public void createForm(@NotNull final FormLayout formLayout, @NotNull final Binder<SpeakerRecord> binder) {
final var firstName = new TextField("First name");
final var lastName = new TextField("Last name");
final var company = new TextField("Company");
final var bio = new RichTextEditor();
final var photo = new ImageUploadField("Photo");
final var email = new EmailField("Email");
final var twitter = new TextField("Twitter");
final var linkedIn = new TextField("LinkedIn");
final var website = new TextField("Website");
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");
firstName.setRequiredIndicatorVisible(true);
firstName.setValueChangeMode(EAGER);
lastName.setRequiredIndicatorVisible(true);
lastName.setValueChangeMode(EAGER);
photo.setMaxPreviewSize("150px", "150px");
email.addValueChangeListener(changeEvent -> {
final var newEmail = changeEvent.getValue();
final var photoValue = photo.getValue();
if (!newEmail.isBlank() && (photoValue.isBlank() || photoValue.startsWith(GRAVATAR_URL))) {
photo.setValue(GravatarUtil.getGravatarAddress(newEmail, 150));
} else if (newEmail.isBlank() && photoValue.startsWith(GRAVATAR_URL)) {
photo.setValue("");
}
});
formLayout.add(firstName, lastName, company, new CustomLabel("Bio"), bio, photo, email, twitter, linkedIn, website, address, zipCode, city, state, country);
binder.forField(firstName).withValidator(new StringLengthValidator("Please enter the first name of the speaker (max. 255 chars)", 1, 255)).bind(SpeakerRecord::getFirstName, SpeakerRecord::setFirstName);
binder.forField(lastName).withValidator(new StringLengthValidator("Please enter the last name of the speaker (max. 255 chars)", 1, 255)).bind(SpeakerRecord::getLastName, SpeakerRecord::setLastName);
binder.forField(company).withValidator(new StringLengthValidator("The company name is too long (max. 255 chars)", 0, 255)).bind(SpeakerRecord::getCompany, SpeakerRecord::setCompany);
binder.forField(bio.asHtml()).withValidator(new StringLengthValidator("The bio is too long (max. 100'000 chars)", 0, 100_000)).bind(SpeakerRecord::getBio, SpeakerRecord::setBio);
binder.forField(photo).withValidator(value -> value.isEmpty() || value.startsWith("data:") || value.startsWith("https://"), "The photo must be uploaded or the photo address must be secure (HTTPS)").withValidator(new StringLengthValidator("The photo is too big (max. 250 KB)", 0, 250_000)).bind(SpeakerRecord::getPhoto, SpeakerRecord::setPhoto);
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(SpeakerRecord::getEmail, SpeakerRecord::setEmail);
binder.forField(twitter).withValidator(new StringLengthValidator("The twitter username is too long (max. 15 chars)", 0, 15)).bind(SpeakerRecord::getTwitter, SpeakerRecord::setTwitter);
binder.forField(linkedIn).withValidator(value -> value.isEmpty() || value.startsWith("https://"), "The LinkedIn address must start with \"https://\"").withValidator(new StringLengthValidator("The LinkedIn address is too long (max. 255 chars)", 0, 255)).bind(SpeakerRecord::getLinkedin, SpeakerRecord::setLinkedin);
binder.forField(website).withValidator(value -> value.isEmpty() || value.startsWith("https://"), "The website address must start with \"https://\"").withValidator(new StringLengthValidator("The website address is too long (max. 255 chars)", 0, 255)).bind(SpeakerRecord::getWebsite, SpeakerRecord::setWebsite);
binder.forField(address).withValidator(new StringLengthValidator("The address is too long (max. 255 chars)", 0, 255)).bind(SpeakerRecord::getAddress, SpeakerRecord::setAddress);
binder.forField(zipCode).withValidator(new StringLengthValidator("The zip code is too long (max. 255 chars)", 0, 255)).bind(SpeakerRecord::getZipCode, SpeakerRecord::setZipCode);
binder.forField(city).withValidator(new StringLengthValidator("The city is too long (max. 255 chars)", 0, 255)).bind(SpeakerRecord::getCity, SpeakerRecord::setCity);
binder.forField(state).withValidator(new StringLengthValidator("The state is too long (max. 255 chars)", 0, 255)).bind(SpeakerRecord::getState, SpeakerRecord::setState);
binder.forField(country).withValidator(new StringLengthValidator("The country is too long (max. 255 chars)", 0, 255)).bind(SpeakerRecord::getCountry, SpeakerRecord::setCountry);
}
Aggregations