6

I have a view model with remote validation enabled. In my view I also disabled OnKeyUp

    $(function() {
        $.validator.setDefaults({ onkeyup: false });
    })

But if I focus on the text box, and move the focus to another control the remote validation is not fired at all.

Is there a way I can ask remote validation to fire when I configured it to onBlur and empty string?

hardywang
  • 3,996
  • 7
  • 54
  • 88
  • You can make an ajax call to the method which you call through remote validation using blur event of jquery. The validations work after you have clicked on the submit once. – Nikitesh May 29 '14 at 14:27

1 Answers1

0

In order to do this you would need to modify the jquery-validate.js file.

The code associated with remote validation:

remote: function(value, element, param) {
  if ( this.optional(element) )
    return "dependency-mismatch";

  var previous = this.previousValue(element);
  ....
  // ajax call
  ....
}

The first if block tests if the element is optional, which it will be unless a [Required] attribute has been applied to the property, or the property is a value type (I assume you property is typeof string) so the function returns and the code to make the ajax call is never reached. Note that even if you added the [Required] attribute, this code block would never called because required: is validated first and you would just get the "The XXX filed is required" message.

If you comment out the first if block, and focus out with an empty string, the remote validation will be fired.