xVal client script overwrites jquery.validate options

Nov 9, 2009 at 8:53 PM

I am not exactly sure what to call this, a bug, missing feature, or possibly misuse on my part, but either way I just wanted to make this known, if it's not already.

We wanted to override the onkeyup for validation on the client side, so that our remote validation didn't hit the server on every key stroke.  Jquery.validation allows this to happen easily by doing something like the following:

   onkeyup: false

We noticed that when validating remotely it was still doing the "eager" validation that we had thought we turned off.  After a little poking around we found the following snippet in the xVal.jquery.validate.js:


                var validationOptions = {
                    errorClass: "field-validation-error",
                    errorElement: "span",
                    highlight: function(element) { $(element).addClass("input-validation-error"); },
                    unhighlight: function(element) { $(element).removeClass("input-validation-error"); }
                if (options.ValidationSummary)
                    validationOptions.wrapper = "li";
                    validationOptions.errorLabelContainer = "#" + options.ValidationSummary.ElementID + " ul:first";
                var validator = formElement.validate(validationOptions);


NOTICE:  The last line here overrides the validate options.

We got around this by adding the following code in the declaration of the validationOptions:

                              onkeyup: false

I guess if I were to make this into a question, it would probably be something like this: 

Is it the intention to override the defaults specified? 

If so, does it make sense to allow the consumer to specify the additional options that they may or may not want to use?