vaadin / flow

Vaadin Flow is a Java framework binding Vaadin web components to Java. This is part of Vaadin 10+.
Apache License 2.0
608 stars 166 forks source link

Validation support for warnings (or in general more ErrorLevels) #10598

Open stefanuebe opened 3 years ago

stefanuebe commented 3 years ago

Using validators together with binders currently only allow validation / handling of errors. There are user scenarios, where entering a value should not lead to an invalid form, but at least should show a warning or allow the developer to react programmatically to such warnings. In a more general way, it could be extended to allow using all existing ErrorLevels as a ValidationResult (e. g. when an app shall differentiate between normal errors and critical ones).

Creating a ValidationResult with for instance ErrorLevel.WARNING is already possible, but the Binder / Validator API does neither support showing this warning with a respective style (looks like an error) nor does it allow to check, whether there have been warnings or not.

Therefore the requested enhancement is to extend the Validator/Binder API to allow a more generic way of using ErrorLevels, for instance by

General example use cases:

knoobie commented 3 years ago

We had this requirement as well, instead of failing the whole process the customer wanted to show that those fields "aren't filled optimal" like e.g.

javier-godoy commented 3 years ago

I created a small POC in #10683 (just the part of propagating error levels through the theme attribute so that they can be styled as warnings or info messages; no changes to the Java API)

image

pleku commented 3 years ago

We find the the API proposed in the PR is problematic https://github.com/vaadin/flow/pull/10683#discussion_r625601266 but it should not be a big task to refactor it to something more versatile like suggested.