Skip to content

useAsyncValidator ​

Category
Export Size
1.34 kB
Package
@vueuse/integrations
Last Changed
11 months ago

Wrapper for async-validator.

Demo ​

Available in the @vueuse/integrations add-on.

Install ​

bash
npm i async-validator@^4

Usage ​

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

Type Declarations ​

Show Type Declarations
typescript
export type AsyncValidatorError = Error & {
  errors: ValidateError[]
  fields: Record<string, ValidateError[]>
}
export interface UseAsyncValidatorExecuteReturn {
  pass: boolean
  errors: AsyncValidatorError["errors"] | undefined
  errorInfo: AsyncValidatorError | null
  errorFields: AsyncValidatorError["fields"] | undefined
}
export interface UseAsyncValidatorReturn {
  pass: Ref<boolean>
  isFinished: Ref<boolean>
  errors: Ref<AsyncValidatorError["errors"] | undefined>
  errorInfo: Ref<AsyncValidatorError | null>
  errorFields: Ref<AsyncValidatorError["fields"] | undefined>
  execute: () => Promise<UseAsyncValidatorExecuteReturn>
}
export interface UseAsyncValidatorOptions {
  /**
   * @see https://github.com/yiminghe/async-validator#options
   */
  validateOption?: ValidateOption
  /**
   * The validation will be triggered right away for the first time.
   * Only works when `manual` is not set to true.
   *
   * @default true
   */
  immediate?: boolean
  /**
   * If set to true, the validation will not be triggered automatically.
   */
  manual?: boolean
}
/**
 * Wrapper for async-validator.
 *
 * @see https://vueuse.org/useAsyncValidator
 * @see https://github.com/yiminghe/async-validator
 */
export declare function useAsyncValidator(
  value: MaybeRefOrGetter<Record<string, any>>,
  rules: MaybeRefOrGetter<Rules>,
  options?: UseAsyncValidatorOptions,
): UseAsyncValidatorReturn & PromiseLike<UseAsyncValidatorReturn>

Source ​

Source • Demo • Docs

Contributors ​

Anthony Fu
Jaw
Jelf
Doctorwu
류한경
Bakhtiyor Ruziev
Bakhtiyor Ruziev
Hawtim
vaakian X
Curt Grimes

Changelog ​

v10.0.0-beta.4 on 4/13/2023
4d757 - feat(types)!: rename MaybeComputedRef to MaybeRefOrGetter
10e98 - feat(toRef)!: rename resolveRef to toRef
0a72b - feat(toValue): rename resolveUnref to toValue
v10.0.0-beta.2 on 3/28/2023
16461 - feat: add manual option (#2903)
v10.0.0-beta.1 on 3/23/2023
79176 - feat: add immediate and execute (#2899)
v10.0.0-beta.0 on 3/14/2023
93b45 - fix: incorrect condition for choosing constructor (#2788)
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)

Released under the MIT License.