Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Customize jQuery Validation's errorPlacement only for some fields

I'd like to customize the errorPlacement only for certain fields, and defer to the plugin's default placement for the rest. Something like:

errorPlacement : function(error, element) {
    if($(element).prop("id") === "mySpecialField") {
        $("#mySpecialErrorMessageHolder").append(error);
    }
    else {
        // this is not valid syntax but it's what I really want...
        super.errorPlacement(error, element);
    }
}

Is this possible?

like image 352
Evan Haas Avatar asked Jan 03 '13 14:01

Evan Haas


1 Answers

errorPlacement : function(error, element) {
    if($(element).prop("id") === "mySpecialField") {
        $("#mySpecialErrorMessageHolder").append(error);
    }
    else {
        error.insertAfter(element); // default error placement.
    }
}

Looking at the source, the default behavior is to use insertAfter.

like image 55
Andrew Whitaker Avatar answered Oct 08 '22 20:10

Andrew Whitaker