views:

7

answers:

0

I am using a validation summary and client side validation as written about here. My problem was then that I wanted a client side validation that supported comparing the equality of 2 fields : email address and password with confirms for both.

So, following Soe Tun, I was able to get my data annotations to automatically run client side and show my errors in a validation summary. Pretty cool.

Then I did everything ukadc showed, with a little help from Brad Wilson to find out where I registered my validator.

Now, it all works server side - that is if the client side validation passes it posts back and then performs my comparisons and if they fail the errors show in the summary. If the client side fails, it does not post back and shows errors in the summary, but not the errors on comparing the fields

I need to figure out how to register my validator client side. If I were using MicrosoftMvcValidation.js I could just do this:

Sys.Mvc.ValidatorRegistry.validators.mustMatch = function (rule) {
var propertyIdToMatch = rule.ValidationParameters.propertyIdToMatch;
var message = rule.ErrorMessage;

return function (value, context) {

    var thisField = context.fieldContext.elements[0];
    var otherField = $get(propertyIdToMatch, thisField.form);

    if (otherField.value != value) {
        return false;
    }

    return true;

};

But I am not using it. Because I want my errors in validation summaries, I have to use MicrosoftMvcJqueryValidation.js with a slight modification to make it work with the validation summary. So, what do I need to do to get my custom rule to work client side?