Skip to content

Why do we need to reconcile the two different types returned by .validate() ? #324

@lafsar

Description

@lafsar

Versions:

  • VueJs: 2.1.10
  • Vee-Validate:2.0.0.23-beta

Description:

I have a custom validation rule that returns a resolved promise. However, when I combine this custom validation with a native validation rule (like required) - In some cases, $validator.validate() returns a Boolean, but other times it returns a Promise.

This results in console errors because you cannot call .then() on a Boolean, which means I have to do a typecheck on $validator.validate() everytime I need to access the errors in the .then() callback.

Returning two different types from one function call seems like a bad design pattern.

Steps To Reproduce:

Create a custom validation rule that returns a Promise.
Extend the validator to use the custom rule.
use validator.attach() to bind the custom rule, along with the native "required" rule.

Attempt to call .then() on $validator.validate('customRule');

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions