开发者

JQuery: Specify placement of error messages inline using Metadata and Validate plugins

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 sele开发者_如何学Goct 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);  
  }
});
});


You may have already abandoned this question, and maybe this has something to do with the metadata plugin (I'm not familiar with it), but I wasn't aware that you could call the appendTo function on something that wasn't an html element. It's possible that through metadata you don't have an html element until after it does it's magic.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜