2011-01-21 74 views
5

我正在使用jQuery Form Wizard 3.0.4 plugin進行多步註冊過程。它使用內置的jQuery驗證器插件,在逐步執行時工作正常。 編輯:這意味着我已經使用validationEnabled:true,formOptions和validationOptions,並且這些工作正在進行。我需要在常規功能之外運行相同的驗證。如何在使用表單嚮導時運行jquery validate()?

問題是我需要運行驗證器並在兩點手動顯示錯誤。我有一個特殊的領域,並在AJAX提交之前。我試過以下,它什麼都不做:

$("#registrationForm").validate(); 

窗體嚮導腳本(jquery.form.wizard-3.0.4.js)似乎這樣做要到下一步驟:

this.element.validate().focusInvalid(); 

所以我想這一點,這也無助:

$("#registrationForm").element.validate().focusInvalid(); 

任何想法?

  1. 如何運行單擊下一步時發生的驗證?
  2. 我將如何調用驗證並顯示特定字段錯誤的函數?
+0

在JQM頁面中使用jquery formwizard插件可行嗎?如果是這樣,移動網頁會不會太重? – Raman 2012-02-25 07:33:00

回答

3

我認爲下面的示例代碼可能適合你,當點擊id =「validate_form」的按鈕或元素時,觸發驗證。這基本上是用戶在下一次點擊時運行的代碼(在插件中)。

$(function(){ 
     $("#validate_form").click(function(){ // when the button is clicked... 
      var wizard = $("#demoForm"); // cache the form element selector 
      if(!wizard.valid()){ // validate the form 
       wizard.validate().focusInvalid(); //focus the invalid fields 
      } 

     }) 
    }) 

如果你只需要驗證一個單一的輸入字段,那麼你可以使用下面的代碼(使用id =「validate_email」點擊在這種情況下按鈕):

$(function(){ 
     $("#validate_email").click(function(){ // when the button is clicked... 
      var wizard = $("#demoForm"); // cache the form element selector 
      if(!wizard.validate().element("#myemail")){ // validate the input field 
       wizard.validate().focusInvalid(); // focus it if it was invalid 
      } 

     }) 
    }) 

希望這幫助。

/Jan

0

你看過插件的文檔嗎?在設置中有一個簡單的開關,可以讓您在定義表單嚮導時進行這種驗證。

http://thecodemine.org/#_demoForm=first

然後點擊「選項」,並期待在「validationEnabled」啓用驗證,然後看看「validationOptions」設置選項。

+0

是的,我已經這樣做了:「它使用內置的jQuery驗證器插件,在逐步執行時工作正常。」 – jwinn 2011-01-21 19:34:12

相關問題