2010-12-09 31 views
2

我正在使用帶有bassistance驗證的formtowizard jquery插件。我重視我的下一個按鈕,但是這驗證我的形式我只希望它來驗證當前字段集而不是整個形式的click事件...字段集之間的驗證

我的形式設置這樣

<form id="SignupForm" method="POST" action=".................."> 

    <fieldset> 
    <legend>Application</legend> 
     <div> 

     </div> 
    </fieldset> 

    <fieldset> 
    <legend>Step Two</legend> 
     <div> 

     </div> 
    </fieldset> 

這就是我用的那一刻

$("a.next").click(function() { 
    $("#SignupForm").validate(); 
    }); 

這是我的按鈕被稱爲

function createNextButton(i) { 
      var stepName = "step" + i; 
      $("#" + stepName + "commands").append("<a href='#' id='" + stepName + "Next' class='next'>Next</a>"); 

      $("#" + stepName + "Next").bind("click", function(e) { 
       /* VALIDATION */ 
       if (options.validationEnabled) { 
        var stepIsValid = true; 
        $("#"+stepName+" :input").each(function(index) { 
         checkMe = element.validate().element($(this)); 
         //stepIsValid = !element.validate().element($(this)) && stepIsValid; 
         stepIsValid = checkMe && stepIsValid; 
        }); 
        //alert("stepIsValid === "+stepIsValid); 
        if (!stepIsValid) { 
         return false; 
        }; 
       }; 

       $("#" + stepName).hide(); 
       $("#step" + (i + 1)).show(); 
       if (i + 2 == count) 
        $(submmitButtonName).show(); 
       selectStep(i + 1,'next'); 
      }); 
     } 

任何想法的人?

+0

任何想法嗎? – 2010-12-09 13:22:33

回答

1

好,我已經成功地解決我的問題,如果其他人想知道......

function createNextButton(i) { 
    var stepName = "step" + i; 
    $("#" + stepName + "commands").append("<a href='#' id='" + stepName + "Next' class='next'>Next</a>"); 

    $("#" + stepName + "Next").bind("click", function(e) { 

     if (options.validationEnabled) { 
      var stepIsValid = true; 
      $("#"+stepName+" :input").each(function(index) { 
       checkMe = element.validate().element($(this)); 
       //stepIsValid = !element.validate().element($(this)) && stepIsValid; 
       stepIsValid = checkMe && stepIsValid; 
      }); 
      alert("stepIsValid === "+stepIsValid); 
      if (!stepIsValid) { 
       return false; 
      }; 
     }; 

     $("#" + stepName).hide(); 
     $("#step" + (i + 1)).show(); 
     if (i + 2 == count) 
      $(submmitButtonName).show(); 
     selectStep(i + 1,'next'); 
    }); 
}