JQuery: Specify placement of error messages inline using Metadata and Validate plugins
        Posted  
        
            by jalperin
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by jalperin
        
        
        
        Published on 2009-11-13T15:55:19Z
        Indexed on 
            2010/04/21
            13:13 UTC
        
        
        Read the original article
        Hit count: 350
        
jQuery
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);  
  }
});
});
© Stack Overflow or respective owner