jQuery.Validate 1.7 error does not show in internet explorer

There is a bug in the jQuery validate plugin when running in internet explorer. When the validate function is called and errors are found, the invalid label error does not show, or rather it shows, it is just empty.

After considerable digging around  I found the culprit. jquery.Validate uses the function defaultMessage to determine which error message to display, it in turn calls the findDefined function to determine which of the parameters is defined and it uses that one as the message.

The bug is in findDefined function, it uses this line to determine weather to use that message or move to next one:

if (arguments[i] !== undefined) {

in internet explorer this comparison is incorrect. The correct comparison to get the desired behavior would be

if (arguments[i] != undefined) {

I’ve tested this last line in all the major browsers and it works great. Hopefully this will save you some time when debugging this particular problem.

Here is the fixed function:

findDefined: function() {
for (var i = 0; i < arguments.length; i++) {
if (arguments[i] != undefined) {
return arguments[i];
}

2 responses to this post.

  1. Posted by Oscar on October 24, 2011 at 10:44 pm

    Unluckily it doesn’t fix the validation problem between jQuery Validate and Internet Explorer. Just a very simple form validation with only one field and check if this field is fielded in, Internet Explorer returns true, the other browsers return false, I don’t know why is that. I tried to set the charset to ISO-8859-1, and no, it didn’t fix.

    By the way thanks for this article.

    Reply

  2. Sorry it did not work for you Oscar.

    jQuery.Validation can be a bit troublesome sometimes.

    Regards,
    Mitch

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.