gospodin
gospodin

Reputation: 1201

Validation exception after upgrading to jQuery 1.8.2

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?

Upvotes: 1

Views: 516

Answers (1)

mccannf
mccannf

Reputation: 16659

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)
            );
        });
    }
}); 

Upvotes: 1

Related Questions