Hello, how can I show the validation error of an form directly beside the TextField instead of showing it just as an ToolTip?
Thanks for any help!
Hello, how can I show the validation error of an form directly beside the TextField instead of showing it just as an ToolTip?
Thanks for any help!
Hi, two ways:
TextField emailField = new TextField("Email");
Label emailStatus = new Label();
binder.forField(emailField)
.withValidator(new EmailValidator("Must be a valid email address"))
.withStatusLabel(emailStatus) // ****** this is one way ******
.bind(Person::getEmail, Person::setEmail);
TextField nameStatus = new TextField("Name");
Label nameStatus = new Label();
binder.forField(nameField)
.withValidator(
name -> name.length() >= 3, "Must have at least three characters")
.withValidationStatusHandler(status -> { // ****** and this is the other way ******
nameStatus.setValue(status.getMessage().orElse(""));
nameStatus.setVisible(status.isError());
})
.bind(Person::getName, Person::setName);
So simple and works perfectly.
Thanks!
Fight for Simplicity