Check if form is valid

image

Is there a method somewhere that tells me if all the required fields are filled and have the proper value?
something like orderForm.isValid()

thanks

Hello @eparamo

Unfortunately, the Form component does not implement the Validatable interface. You can write your implementation in a screen controller (see FieldGroup#validate(), FieldGroup#isValid()).

    @Inject
    protected Form form;

    protected boolean isFormValid() {
        for (Component component : form.getComponents()) {
            if (component instanceof Validatable) {
                try {
                    ((Validatable) component).validate();
                } catch (ValidationException e) {
                    return false;
                }
            }
        }

        return true;
    }

Or you can use StandardEditor#validateUiComponents() and StandardEditor#validateScreen() methods.

Regards,
Gleb

Thank you very much for your reply. I am not using Editor Screens. I have a form in a framgent. Do I need to add this function to all my fragments?

Hello @eparamo

You can use following methods of Fragment class:

  1. boolean validateAll()
  2. boolean validate(List<Validatable> fields)

Regards,
Gleb

thank you so much for your help !!!

Im on a fragmentScreen

this.getFragmaent.validateAll()

Can I use your beautiful wizard? Please give me a link…

Im trying to do the wizard on my own. I dont know if its the best solution. There is a project attached to the end of this discussion.