JQuery: Specify placement of error messages inline using Metadata and Validate plugins
- by jalperin
I'm doing form validation using JQuery with the validate and metadata plugins. I'm using the metadata plugin so I can specify the rules and messages inline in the html form instead of in the javascript in the page . I'm getting an error when I try to specify the location of the error message using errorPlacement. (If I specify it in the section it works fine, but not if I specify it inline.)
Here's what my html looks like:
<input name="list" id="list1" type="checkbox"
validate="{required:true, minlength:1,
messages:{required:'Please select at least one newsletter.', minlength:'Please select at least one newsletter.'},
errorPlacement: function(error, element) { error.appendTo('#listserror');} }">
As reported by the validate debug function, the error is: "error.appendTo is not a function."
It works fine if I specify it in the section like this:
$().ready(function() {
$("#subscribeForm").validate({
errorPlacement: function(error, element) {
if (element.attr("name") == "list" )
error.appendTo("#listserror");
else
error.insertAfter(element);
}
});
});