Skip to content
On this page

useAsyncValidator

Category
Export Size
1.2 kB
Package
@vueuse/integrations
Last Changed
2 days ago

Wrapper for async-validator.

Demo

Available in the @vueuse/integrations add-on.

Install

bash
npm i async-validator
npm i async-validator

Usage

ts
import { useAsyncValidator } from '@vueuse/integrations/useAsyncValidator'
import { useAsyncValidator } from '@vueuse/integrations/useAsyncValidator'

Type Declarations

typescript
export type AsyncValidatorError = Error & {
  errors: ValidateError[]
  fields: Record<string, ValidateError[]>
}
export interface UseAsyncValidatorReturn {
  pass: Ref<boolean>
  errorInfo: Ref<AsyncValidatorError | null>
  isFinished: Ref<boolean>
  errors: Ref<AsyncValidatorError["errors"] | undefined>
  errorFields: Ref<AsyncValidatorError["fields"] | undefined>
}
export interface UseAsyncValidatorOptions {
  /**
   * @see https://github.com/yiminghe/async-validator#options
   */
  validateOption?: ValidateOption
}
/**
 * Wrapper for async-validator.
 *
 * @see https://vueuse.org/useAsyncValidator
 * @see https://github.com/yiminghe/async-validator
 */
export declare function useAsyncValidator(
  value: MaybeComputedRef<Record<string, any>>,
  rules: MaybeComputedRef<Rules>,
  options?: UseAsyncValidatorOptions
): UseAsyncValidatorReturn & PromiseLike<UseAsyncValidatorReturn>
export type AsyncValidatorError = Error & {
  errors: ValidateError[]
  fields: Record<string, ValidateError[]>
}
export interface UseAsyncValidatorReturn {
  pass: Ref<boolean>
  errorInfo: Ref<AsyncValidatorError | null>
  isFinished: Ref<boolean>
  errors: Ref<AsyncValidatorError["errors"] | undefined>
  errorFields: Ref<AsyncValidatorError["fields"] | undefined>
}
export interface UseAsyncValidatorOptions {
  /**
   * @see https://github.com/yiminghe/async-validator#options
   */
  validateOption?: ValidateOption
}
/**
 * Wrapper for async-validator.
 *
 * @see https://vueuse.org/useAsyncValidator
 * @see https://github.com/yiminghe/async-validator
 */
export declare function useAsyncValidator(
  value: MaybeComputedRef<Record<string, any>>,
  rules: MaybeComputedRef<Rules>,
  options?: UseAsyncValidatorOptions
): UseAsyncValidatorReturn & PromiseLike<UseAsyncValidatorReturn>

Source

SourceDemoDocs

Contributors

Anthony Fu
Jelf
Bakhtiyor Ruziev
Hawtim
vaakian X
Curt Grimes

Changelog

v9.13.0 on 2/18/2023
dbcdb - fix: fix Schema importing from async-validator (#2761)
v9.11.0 on 1/17/2023
d5321 - fix(components): mark defineComponent as pure (#2623)
v8.9.1 on 7/8/2022
a9ccc - feat(all): use MaybeComputedRef (#1768)
v8.7.4 on 6/18/2022
5c742 - feat: new options (#1695)
v8.6.0 on 5/31/2022
f4226 - feat: new function (#1497)

Released under the MIT License.