Form validation with Binder

How to finish validation with sending all form data in Vaadin 8? Unfortunetly I dont understand binder concept :frowning: I wrote a field validation but what now? It works. My user see when I demand that he fill out a field but is there any easy way to validate my all form? How can I “tell” to my save button that my form is valid?

In my editor Im defining a validator

[code]
@SpringComponent
@PrototypeScope
public class VaadinStringEditor extends TextField implements HasValueComponent {

private Binder<String> binder;

@PostConstruct
public void init() {
    setWidth("100%");
    binder = new Binder<>();
}

@Override
public void initDefaults() {
    setValue("");
    binder.validate();
}

@Override
public void setConfiguration(EditorConfiguration editorConfiguration) {
    Validator<String> validator = ((TextFieldConfiguration) editorConfiguration).getValidator();
    if (validator != null) {
        binder.forField(this).withValidator(validator).asRequired("Mandatory").bind(s -> getValue(),
                (b, v) -> setValue(v));

    }

}

}
[/code]and in my quesions class

    question.setEditorConfiguration(new TextFieldConfiguration(textRequiredValidator()));

    private Validator<String> textRequiredValidator() {
        return Validator.from(v -> v != null && StringUtils.trimAllWhitespace((String) v).length() != 0,
                 "It cannot be empty!!!");
    

You should have one binder for your form, not 1 binder for each field.

For example, if you have a bean TestBean with 3 properties test1, test2, test3.
Then you have a Binder.
You can find examples here:
https://vaadin.com/blog/vaadin-8-binder
or here
https://vaadin.com/docs/v8/framework/datamodel/datamodel-forms.html