tags:

views:

291

answers:

1

I have a Page with a Wizard component. The user can navigate the panels of the wizard by using the next and previous buttons which I have performing full (non-ajax) form submissions so that the app is back-button friendly.

When the next button is clicked, I would like to attempt ajax form validation (if javascript is enabled). I tried doing:

nextButton.add( new AjaxFormValidatingBehavior( form, "onsubmit") );

to add such validation. The behaviour works - however, when validation errors occur the browser still submits the entire form.

What is the Wicket way to prevent the browser from submitting the form in this case?

A: 

Override the onError() method on either the form or the AjaxFormValidatingBehavior. If you do it on the behavior, I am not sure if that will prevent the form from submitting or not.

new AjaxFormValidatingBehavior( form, "onsubmit") {
   public void onSubmit() {}
   public void onError() {}
}
schmimd04
Thanks, but what could I put in onError() to stop the submission though? It appears that on the client side there is no script preventing the full form submission from happening. I'm not sure how I could prevent that from happening unless there are no validation errors. I've tried implementing getFailureScript by returning "return false;" to attempt to squash the event, but to no avail.
Brian Laframboise
Add a `FeedbackPanel` to the top of your form. Then in `onError()` you add it to the target so it gets refreshed through Ajax (`target.addComponent(feedbackPanel)`). If there are validation errors, the FeedbackPanel should show the corresponding error messages. You can also add custom messages to the panel (`feedbackPanel.error("Validation Error")`)
schmimd04