Remote Validation OnBlur and Empty String
Asked Answered
L

1

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?

Labia answered 17/10, 2012 at 0:12 Comment(1)
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.Pedometer
A
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.

Abiosis answered 7/12, 2014 at 6:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.