-
Notifications
You must be signed in to change notification settings - Fork 728
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When I have just one field on the UI, I want to easily validate the value of the field, without having to use binder or listening to event and manually show error message #8294
Comments
tldr: We could make it possible to create a This is something that was left out of 8.0, you just basically should use a TextField tf = new TextField();
tf.addValueChangeListener(event -> {
if (event.getValue().isEmpty()) {
tf.setComponentError(new UserError("Empty value not allowed"));
} else {
tf.setComponentError(null);
Notification.show(event.getValue());
}
}); You can use TextField textField = new TextField();
Binder<String> binder = new Binder<String>();
Binding<String, String> binding = binder.forField(textField)
.withValidator((value, context) -> value.isEmpty()
? ValidationResult.error("Empty value not allowed")
: ValidationResult.ok())
.bind(string -> string, this::onValueChange);
binder.setBean("Initial Value"); // goes to textfield directly |
Thanks Pleku, good ideas. |
What I seem to miss in this approach is the ability to check wether a field is valid. Something like |
@Thibstars, you can use standard Vaadin 8 validation API for that. Use |
@elmot Thanks for the suggestion. However I do still think that produces lengthy code as well. It works for me and I do think it is better than just use valuechangelisteners. |
@pleku Thank you very much, but I am unable to reproduce the snippet. In: |
@fgrazi that is just an example, you should replace the In the example it is just something that consumes a |
Thanks pleku, but I still don't understand. Once I have a Binder.BindingBuilder |
Another way to do that is to have an additional method to Binder. For instance, for now, I have to do that:
But ideally a noBind() method can be added:
|
Hello there! It looks like this issue hasn't progressed lately. There are so many issues that we just can't deal them all within a reasonable timeframe. There are a couple of things you could help to get things rolling on this issue (this is an automated message, so expect that some of these are already in use):
Thanks again for your contributions! Even though we haven't been able to get this issue fixed, we hope you to report your findings and enhancement ideas in the future too! |
This feature has been implemented as add-on in Directory https://vaadin.com/directory/component/fieldbinder |
Hi,
I believe this is the right place to leave V8 feedback.
Shouldn't it be possible to validate/convert values in Fields without having to bind to a bean?
I have a form with a single field. It seems weird to have to bind this one field to a bean in order to validate it.
Thanks!
Dan.
The text was updated successfully, but these errors were encountered: