[英]Trying to display errors with jquery.validation
I'm trying to display errors using the jquery.validation plugin but I am not getting back any messages. 我正在尝试使用jquery.validation插件显示错误,但没有收到任何消息。
When I click on submit I get invalid alerts on the blank fields but no message in the summary div. 当我单击提交时,我在空白字段上收到无效警报,但摘要div中没有消息。 Can anyone tell me what I've missed?
谁能告诉我我错过了什么?
Thanks 谢谢
<div class="form-group form-group-sm">
<label class="control-label requiredField" for="SW">
Social Worker
<span class="asteriskField">
*
</span>
</label>
<input class="form-control" id="SW" name="SW" type="text" required="required"/>
</div>
<div class="form-group form-group-sm">
<label class="control-label requiredField" for="NMN">
Named Nurse
<span class="asteriskField">
*
</span>
</label>
<input class="form-control" id="NMN" name="NMN" type="text" required="required"/>
</div>
<div id="summary"></div>
<div class="form-group">
<div>
<button class="btn btn-primary " name="submit" id="submit" type="submit">
Submit
</button>
<script>
$("#mform").validate({
showErrors: function(errorMap, errorList) {
$("#summary").html("Your form contains "
+ this.numberOfInvalids()
+ " errors, see details below.");
this.defaultShowErrors();
}
});
</script>
Working Fiddle : http://jsfiddle.net/sandenay/4psggt9q/ 工作小提琴 : http : //jsfiddle.net/sandenay/4psggt9q/
I have included jQuery
and jQuery Validate
plugins 我包括了
jQuery
和jQuery Validate
插件
Your JS Code: 您的JS代码:
$(document).ready(function(){
$("#submit").click(function(){
$("#mform").validate({
showErrors: function(errorMap, errorList) {
$("#summary").html("Your form contains "
+ this.numberOfInvalids()
+ " errors, see details below.");
this.defaultShowErrors();
}
});
});
});
HTML: HTML:
<form id="mform">
.........other html code............
// Observe that I have removed type="submit" below code
<button class="btn btn-primary " name="submit" id="submit">
Submit
</button>
</form>
defaultShowErrors()
shows errors besides input
fields. defaultShowErrors()
除了input
字段外,还显示错误。
numberOfInvalids()
shows the count of all errors. numberOfInvalids()
显示所有错误的计数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.