admin管理员组文章数量:1287596
Can't seem to find out why my jquery.validate script is not showing the messages. Anyone see what I am doing wrong?
Trying to display messages in a separate div:
html:
<form class="cmxform" id="mentForm" method="get" action="">
<label for="vehiclePrice" class="form-control-label vpl">Vehicle Price</label>
<input type="text" class="form-control" id="vehiclePrice" placeholder="$0" onkeypress="return isNumberKey(event)" value="25592" required />
<label for="estimatedTaxesAndFees" class="form-control-label etfl">Estimated Taxes and Fees</label>
<input type="text" class="form-control" id="estimatedTaxesAndFees" placeholder="$0" onkeypress="return isNumberKey(event)" value="2843" required />
</form>
<div id="error-note"></div>
js:
$(document).ready(function() {
$('#mentForm').validate({
errorLabelContainer: "#error-note",
wrapper: "li",
onfocusout: function(element, event) {
this.element(element);
},
rules: {
vehiclePrice: 'required',
estimatedTaxesAndFees: 'required'
},
messages: {
vehiclePrice: 'Please enter vehicle price',
estimatedTaxesAndFees: 'Please enter taxes and fees
}
});
});
fiddle
Can't seem to find out why my jquery.validate script is not showing the messages. Anyone see what I am doing wrong?
Trying to display messages in a separate div:
html:
<form class="cmxform" id="mentForm" method="get" action="">
<label for="vehiclePrice" class="form-control-label vpl">Vehicle Price</label>
<input type="text" class="form-control" id="vehiclePrice" placeholder="$0" onkeypress="return isNumberKey(event)" value="25592" required />
<label for="estimatedTaxesAndFees" class="form-control-label etfl">Estimated Taxes and Fees</label>
<input type="text" class="form-control" id="estimatedTaxesAndFees" placeholder="$0" onkeypress="return isNumberKey(event)" value="2843" required />
</form>
<div id="error-note"></div>
js:
$(document).ready(function() {
$('#mentForm').validate({
errorLabelContainer: "#error-note",
wrapper: "li",
onfocusout: function(element, event) {
this.element(element);
},
rules: {
vehiclePrice: 'required',
estimatedTaxesAndFees: 'required'
},
messages: {
vehiclePrice: 'Please enter vehicle price',
estimatedTaxesAndFees: 'Please enter taxes and fees
}
});
});
fiddle
Share Improve this question edited Jan 28, 2014 at 3:43 isaac weathers asked Jan 28, 2014 at 3:31 isaac weathersisaac weathers 1,4725 gold badges29 silver badges54 bronze badges 3- there is no submit button in the form? – Arun P Johny Commented Jan 28, 2014 at 3:35
-
missing end qoute here
estimatedTaxesAndFees: 'Please enter taxes and fees
? – nix Commented Jan 28, 2014 at 3:35 - There is not submit for this form. It is part of a multipart form that updates content in a div. There is no definitive submit. – isaac weathers Commented Jan 28, 2014 at 3:43
2 Answers
Reset to default 51) Include jQuery in your fiddle
2) Add submit button to your HTML:
<input type="submit" value="Submit" />
3) Add missing '
at the end of your estimatedTaxesAndFees
message:
estimatedTaxesAndFees: 'Please enter taxes and fees' // <-- Here
Updated Fiddle
You need to add name
attribute to your input
to get custom message here:
<input type="text" class="form-control" name="vehiclePrice" id="vehiclePrice"
<input type="text" class="form-control" name="estimatedTaxesAndFees"
Updated Fiddle
you had a unclosed string literal, also in the fiddle jQuery was not included
$(document).ready(function() {
$('#mentForm').validate({
errorLabelContainer: "#error-note",
wrapper: "li",
onfocusout: function(element, event) {
this.element(element);
},
rules: {
vehiclePrice: 'required',
estimatedTaxesAndFees: 'required'
},
messages: {
vehiclePrice: 'Please enter vehicle price',
estimatedTaxesAndFees: 'Please enter taxes and fees'//closing ' was missing
}
});
});
Demo: Fiddle
The validation will trigger if you clear the contents of a textbox/or you add a submit button to the form/or call the valid()
method of the form manually
本文标签: javascriptjqueryvalidate not showing messagesStack Overflow
版权声明:本文标题:javascript - jquery.validate not showing messages - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741289758a2370480.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论