Search in sources :

Example 1 with EmailField

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);
}
Also used : Div(com.vaadin.flow.component.html.Div) TextArea(com.vaadin.flow.component.textfield.TextArea) EmailField(com.vaadin.flow.component.textfield.EmailField) TextField(com.vaadin.flow.component.textfield.TextField) IntegerField(com.vaadin.flow.component.textfield.IntegerField) PasswordField(com.vaadin.flow.component.textfield.PasswordField) NumberField(com.vaadin.flow.component.textfield.NumberField) BigDecimalField(com.vaadin.flow.component.textfield.BigDecimalField)

Example 2 with EmailField

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);
}
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 3 with EmailField

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);
}
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 4 with EmailField

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);
}
Also used : FormLayout(com.vaadin.flow.component.formlayout.FormLayout) Binder(com.vaadin.flow.data.binder.Binder) ComboBox(com.vaadin.flow.component.combobox.ComboBox) 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 5 with EmailField

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);
}
Also used : CustomLabel(org.komunumo.ui.component.CustomLabel) EmailValidator(com.vaadin.flow.data.validator.EmailValidator) ImageUploadField(org.komunumo.ui.component.ImageUploadField) SpeakerRecord(org.komunumo.data.db.tables.records.SpeakerRecord) StringLengthValidator(com.vaadin.flow.data.validator.StringLengthValidator) EmailField(com.vaadin.flow.component.textfield.EmailField) TextField(com.vaadin.flow.component.textfield.TextField) RichTextEditor(com.vaadin.flow.component.richtexteditor.RichTextEditor)

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