开发者

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 bac开发者_运维知识库k, 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?

  • JQuery validation plugin: http://docs.jquery.com/Plugins/validation
  • Spring Webflow: http://www.springsource.org/webflow version 2.x.x

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>


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.


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

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜