开发者

Jquery Validation showing single error infront of City/Zip on a single row

开发者 https://www.devze.com 2023-03-17 02:27 出处:网络
I have City & Zip inputboxes on a single row and there required error is shown infront of them in a TD.

I have City & Zip inputboxes on a single row and there required error is shown infront of them in a TD. Problem is that on error I see 2 required errors which you can see in the below HTML taken in Firebug.

What I want to do is show single error for both City/Zip infront of them.

How to check that City/Zip has already error added in TD infront of them?

FireFox FireBug

<tr>
    <td class="normalformCaptionTd">* City :</td>
    <td class="normalformFieldTd">
        <input id="City" class="normalformFieldCity error" type="text" tabindex="3" name="City">
        <span class="normalformBold">* Zip :</span>
        <input id="Zip" class="normalformFieldCity zip error" ty开发者_如何学Gope="text" tabindex="4" name="Zip">
    </td>
    <td class="msgMiddle">
        <em class="error" for="City" generated="true">Required</em>
        <em class="error" for="Zip" generated="true">Required</em>
    </td>
</tr>


    errorPlacement: function(error, element) {

             if (element.attr("name") == "City" || element.attr("name") == "Zip" )
                //How to check that City/Zip has already error added in TD infront of them?
             else
                error.appendTo( element.parent("td").next("td") );

            },


You can use the element() method of the validator object to check if a field is valid. Like this:

var validator = $("#your_form").data('validator');
if(validator.element($("#City"))){ //Check if #City is valid
   ...
}
if(validator.element($("#Zip"))){ //Check if #City is valid
   ...
}

Hope this helps. Cheers

0

精彩评论

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

关注公众号