victorjonsson / jQuery-Form-Validator

[DISCONTINUED] jQuery plugin that makes it easy to validate user input while keeping your HTML markup clean from javascript code.
972 stars 476 forks source link

New function for adding async validators #609

Open victorjonsson opened 7 years ago

victorjonsson commented 7 years ago

At the moment you can call $.formUtils.asyncValidation(this.name, $input, $form) from within a validation callback. The problem with this are at least the following:

Suggestion would be to add a new function, used to explicitly point out that a validator will do some async processing.

  $.formUtils.addAsyncValidator({
    name : 'server',
    validatorFunction : function(done, value, $input) {
      var serverURL = $input.valAttr('url') || document.location.href;
      requestServer(serverURL, value, function (response) {
        var isValid = response....;
        done(isValid);
      });
    },
    errorMessage: '',
    errorMessageKey: 'badBackend'
  });

The interface would be the same as for addValidator(). The only difference would be the function signature of validatorFunction, which argument list would begin done:Function

xonecas commented 7 years ago

@victorjonsson is this release available for general use yet?

victorjonsson commented 7 years ago

It's available in release 2.3.74