开发者

jQuery.validate errorPosition not working correctly

开发者 https://www.devze.com 2023-01-10 17:14 出处:网络
jQuery.validate errorPosition code: errorPlacement: function(error, element) { error.appendTo(element.siblings(\"label\"));

jQuery.validate errorPosition code:

errorPlacement: 
     function(error, element)
     {
          error.appendTo(element.siblings("label"));  
     },

That code works brilliantly when there is only one element below 开发者_开发百科it's label.

Does NOT work:

<label for="location">Location:</label><br />
<div id="location"></div><br />
<input name="location" id="h_location" hidden /><br />

This works:

<label for="location">Location:</label><br />
<input name="location" id="h_location" hidden /><br />

When the div location is not there the error shows next to the location label. When the location div is there the error message does not show at all.

I've been asking around for help and someone mentioned to me that I should read up on CSS block level elements. I read up on them and I'm not finding a solution. All I gathered from that reading is, how to display either: inline, block or none. I'm apparently not understanding what that person is hinting towards.

Why is the error message not showing when it should and how do I get it to show?

-Thank You, Rich


I found a way to attach the error message to the label:

var elementName = element.attr("name");

error.appendTo($("label[for=" + elementName + "]"));

That works as expected.

I'm still open for other ways to accomplish this.

0

精彩评论

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

关注公众号