开发者

jQuery validator error placement (.rules("add"))

I have a jquery popup, which has a list of text boxes to insert开发者_如何转开发 phone numbers. The user can choose to add more text boxes if they want. Each time they add a text box, I am adding a jquery required validator like so:

$("#phoneNumberTxt" + i).rules("add", {
        required: true,
        messages: {
          required: "Phone number is required."
        }
      });

On the line with the text box, there are multiple text boxes. I am trying to pipe all the errors to a div to the left of all the text boxes (1 div per row). Is there a way to tell the above validator where to display the error message?


I hope you already got the solution for this & i am too late to answer but still for sharing knowledge.

This is the solution:

We can not place errorPlacement in (.rules(“add”)) method.

$("#formId").validate({
    errorPlacement: function (error, element) {

            $("input[id^=elementId]").each(function(i) {
                if(element.attr('id') == 'elementId'+i) {
                    error.appendTo($("#errElement"+i));
                }
            });
        }
 });

I hope this will help other.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜