Jquery Validate custom error message location

后端 未结 7 1745
一个人的身影
一个人的身影 2021-01-30 16:35

This looks very simply, but I can\'t figure it out. I\'m using the jquery validate plugin. I\'m trying to validate and

7条回答
  •  野的像风
    2021-01-30 17:16

    You can simply create extra conditions which match the fields you require in the same function. For example, using your code above...

    $(document).ready(function () {
        $('#form').validate({
            errorPlacement: function(error, element) {
                //Custom position: first name
                if (element.attr("name") == "first" ) {
                    $("#errNm1").text(error);
                }
                //Custom position: second name
                else if (element.attr("name") == "second" ) {
                    $("#errNm2").text(error);
                }
                // Default position: if no match is met (other fields)
                else {
                     error.append($('.errorTxt span'));
                }
            },
            rules
    });
    

    Hope that helps!

提交回复
热议问题