2016-06-28 28 views
0

我已經在asp.net mvc的注意到了jquery.validate奇怪的行爲jquery.validate奇怪的行爲

我的模型字段包含字段StringLength屬性:

[StringLength(200, ErrorMessage = "Cannot be longer than 200 characters.")] 
public string Name{ get; set; } 

,並查看:

@Html.LabelFor(model => model.Name, htmlAttributes: new { }) 
<div class="form-group formgroup-custom"> 
    @Html.TextAreaFor(model => model.Name, 2, 1, new { @class = "form-control" }) 
</div> 
@Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger error-custom" }) 

所以現在如果我點擊我的TextArea並輸入201個字符沒有錯誤發生,然後失去焦點(讓我們說點擊其他字段)錯誤信息出現。然後我回到我的TextArea刪除200個字符下的內容,錯誤信息隱藏和區別在於輸入201後,字符錯誤自動顯示,無需丟失焦點。 它看起來像第一次驗證檢查是在一些loosing focus事件,然後第二次檢查keye up

所以我的問題是如果jquery.validate*有一些錯誤,或者如果有可能,其他腳本以某種方式分解它。

框架: .NET 4.6

+0

這是默認的行爲 - 請參考[文件](HTTPS ://jqueryvalidation.org/documentation/),特別是標題爲_A的部分,當玩弄demo_ –

+0

謝謝!這個頁面可以很方便 – Carlos28

回答

1

這是JQuery驗證的默認行爲。

如果你想只在表格上,以驗證提交,設置「的onkeyup」,「的onclick」和「onfocusout在」爲「假」:

$("#form").validate({ 
    onfocusout: false, 
    onkeyup: false, 
    onclick: false 
})