Vaadin 8 TextField valid

I have a form that I then set up the binding as such:

private TextField city = new TextField("City");

                .withValidator(new StringLengthValidator("Must be no longer than 32 characters.", 0, 32))

The binding works and will notify the UI if it is invalid.

How do I programatically tell if the city is currently valid in the code? What I’m trying to accomplish is to disable a save button if there are any invalid form field values. I attempted to do so by adding a value change listener and then checking to see if there’s an error message on the field. This doesn’t work because the listener fires before the bound validator validates and only reports the previous states error, not the current state. I already wired a validator, and some fields are expensive containing data lookups, so I do not want to run validation twice on every field.

In Vaadin 8, how do I disable a save button if any of the fields are not valid?


You can customize the handling of validation errors by giving a custom ValidationStatusHandler. To do this call
.withValidationStatusHandler(handler) e.g. after withValidator(…). See this link for some more info: