2017-06-16 65 views
0

輸入值的所有錯誤消息消失,我有以下的jQuery驗證表單。當一個文本框

  1. 當我沒有輸入任何值提交表單時,它顯示錯誤消息。但是當我在「金額」文本框中輸入值時,這兩個錯誤消息都消失了。

  2. 而且,在那之後,當我在金額文本明確的價值,只顯示「金額」的錯誤消息,直到我按一下按鈕。

如何解決這個問題?

Fiddle

enter image description here

jQuery代碼

$("#formAddPayment").validate({ 
    rules: { 
    "ddlModeOfPayment": { 
     required: true 
    }, 
    "txtAmount": { 
     required: true 
    } 
    }, 
    messages: { 
    "ddlModeOfPayment": { 
     required: "Please select Mode of Payment." 
    }, 
    "txtAmount": { 
     required: "Please enter Amount." 
    } 
    }, 

    showErrors: function (errorMap, errorList) { 

    var errorListResult = $.map(errorList, function(error){ 
     return "<li>" + error.message+ "</li>"; 
    }); 

    $('#errorSummaryList').html(errorListResult.join('')) 
    $('#errorSummaryList').fadeIn('fast'); 

    //Show error adjuscent to control also 
    //this.defaultShowErrors(); 
    }, 
    submitHandler: function (form) { 
    return false; 
    } 
}); 
+0

其他參考資料:https://stackoverflow.com/questions/3683104/change-location-of-jquery-validation-plugin-error-message?rq = 1 – Lijo

回答

1

所有錯誤消息消失當在一個文本框輸入值

the documentation for showErrors

的參數包含那些元件目前驗證,其可以是單個元件focusoutkeyup做驗證onblur時。

如您所見,showErrors選項按設計工作。消息的新map新的驗證完成後不保留以前的消息。如果一個字段被驗證,那麼該地圖僅包含該字段的消息等。

只使用wrapper and errorLabelContainer選項,它們一起使用時,被設計爲自動保留整個表單的待處理消息的更新列表...

wrapper: "li", // <- the LABEL will be inside of this 
errorLabelContainer: "#errorSummaryList", // <- your UL element 

DEMO:jsfiddle.net/y9o8du3q/

相關問題