2
votes

How to disable inner form validation with Wicket in following case?

Outer form has some fields with validators, including a TextField. When user has the TextField focused and presses Enter, the outer form should submit.

Inner form has also some fields with validators and submit buttons.

Pressing Enter in outer form TextField tries to submit the form but also runs validatators in the inner form and I'd like to prevent that.

Is there any other way than to use setDefaultFormProcessing(false) in the inner form and rewrite validation logic inside onSubmit method?

1

1 Answers

2
votes

When Form component is validating, then it checks all it's nested forms and validate them only if their's methods isEnabledInHierarchy() && isVisibleInHierarchy() returns true. You can't override validate() method ( only onValidate() but it executes after real validation processed ), so the only option I see (with your restrictions) is to disable nested form when outer form is processed.

You have to override process() method for outer form like this:

final Form<Void> innerForm =....;

final Form<Void> outerForm = new Form<Void> ( "outer" )
{
    public void process ( IFormSubmitter submittingComponent )
    {
        innerForm.setEnabled ( false );
        super.process ( submittingComponent );
        innerForm.setEnabled ( true );
    }
}