1

After upgrading to version 1.8.2 of jQuery, my validation plugin (latest version 1.10.0) started giving me exception:

Error: Syntax error, unrecognized expression: div class="warningZone" jquery.js (line 4679)

Here is my javascript:

function validateAll() {
    $("#servicesForm").validate({
        errorLabelContainer: "#servicesErrors",
        wrapper: "div class=\"warningZone\"",
        rules: {
            mainTransport: { mMainTransportReq: true, mMainTransportNotReq: true },
            stay: { mStayReq: true }
        },
        messages: {
            mainTransport: {
                mMainTransportReq: $("#servicesMainTransportReq").text(),
                mMainTransportNotReq: $("#servicesMainTransportNotReq").text()
            },
            stay: { mStayReq: $("#servicesStayReq").text() }
        }
    });

    $("#servicesForm").valid();
    validatePeriods();
    validateServices();
}

Why has my class warningZone started throwing exceptions?

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
gospodin
  • 1,133
  • 4
  • 22
  • 42

1 Answers1

1

If you remove the wrapper and errorLabelContainer options above, you could set defaults and override the showErrors function:

$.validator.setDefaults({
    showErrors: function(errorMap, errorList) {
        if (errorList.length < 1) {
            // clear the error if validation succeeded
            $('div.warningZone').remove();
            return;
        }
        $.each(errorList, function(index, error) {
            $('div.warningZone',"#servicesErrors").remove();
            $('#servicesErrors').append(
                $('<div/>')
                    .addClass('warningZone')
                    .append(error.message)
            );
        });
    }
}); 
mccannf
  • 16,619
  • 3
  • 51
  • 63
  • yes this seems like a workaround but I still dont understand what changed between jQuery ver. 1.7.2 and 1.8 that makes my wrapper function not working? After some tests, if I use "li" in a wrapper function it will not throw exception but if I use "div" or "li" with class - it will!!! I couldn't find any doc in version c hange or any bug listed in a validation plugin. – gospodin Dec 06 '12 at 09:08