views:

44

answers:

0

I'm posting text and have created a remote validator. I've used it now 3 times and I want to consolidate the validator into a specific method. I'm having problems making the data ($("#Title")) and the error handler more generic ($("#editIntroOverlay > form").validate()). Is there a property of the validator object I can access like 'currentElement' or 'currentForm' to reference these elements?

$(document).ready(function(){
jQuery.validator.addMethod("NoInvalidChar", function(value, element){
    $.ajax(
    {
        type: 'POST',
        url: '<%=Url.Action("HasInvalidChars", "Authoring") %>',
        data: { stringToTest: function() { return $("#Title").val() } },
        error: function() {
             $("#editIntroOverlay > form").validate().showErrors({ "IntroTitle": "This field contains invalid text" });
                    }
    });
}

});