views:

12

answers:

0

I am using this method to add a method to the JQuery validator. I'd like to know how to modify the parameters variable to change the error message. Has anyone done this?

(function ($) {
    $.validator.addMethod('requiredwhencontains', function (value, element, parameters) {
        var id = '#' + parameters['dependentProperty'];

        // Get the target value (as a string, as that's what actual value will be)
        var targetvalue = parameters['targetValue'];
        targetvalue = (targetvalue == null ? '' : targetvalue).toString().toLowerCase();

        // Get the actual value of the target control
        var actualvalue = ($(id).val() == null ? '' : $(id).val()).toLowerCase();

        // If the condition is true, reuse the existing required field validator functionality
        if (actualvalue.indexOf(targetvalue) > -1)
            return $.validator.methods.required.call(this, value, element, parameters);

        return true;
    });
})(jQuery);