Skip to content

New function for adding async validators #609

Open
@victorjonsson

Description

@victorjonsson

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:

  • Whether or not a validator will do async processing is determined at runtime (when the validation gets triggered). In some cases you need to find out if an input has an async validator before the validation have been triggered, this is simply not possible.
  • Unnecessary setup code is required every time a validator needs to do async stuff.

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions