user271586
user271586

Reputation:

JQuery form wizard validation: how to skip validation on a 'back' button?

I am using JQuery validation in a wizard made using Spring Webflow. The validation is set to be enabled when the doc is ready, since I want inline validation. It all works fine.

The issue I am facing is the 'Previous' button, if I try to click it; it will not go back, since the validation fails. How can I skip validation when a specific button is pressed? Currently, I created an on click function, but then, Spring webflow cannot return to the previous view.

Any suggestions?

Validation:

$(document).ready(function(){
  // Validation for all the forms.
  $("#user_details").validate({ 
    rules: { ... },
    messages: { ... },
  });
...

flow of wizard:

<view-state id="userdetails" view="">
  ...
  <transition on="prev" to="homepage" validate="false"/>
  <transition on="next" to="nextstate" validate="true"/>
</view-state>

Upvotes: 0

Views: 2804

Answers (2)

JW8
JW8

Reputation: 1506

I faced a similar issue. The way I got around this validation problem was to add class="cancel" to any submit button (e.g., cancel or previous) where I don't want jquery validations to be triggered.

An example looks like this:

<input type="submit" name="_eventId_prev" value="<spring:message code="label.previous"/>" class="cancel" />

I found this solution to be easier - no additional code to maintain.

Upvotes: 2

Pit Digger
Pit Digger

Reputation: 9800

One way to do it, is to callas below the click event of the back button .

$("#user_details").validate().cancelSubmit = true;

Upvotes: 0

Related Questions