partialCheckAsync

Creates a partial check validation action.

const Action = v.partialCheckAsync<TInput, TPathList, TSelection, TMessage>(
  pathList,
  requirement,
  message
);

Generics

Parameters

  • pathList TPathList
  • requirement (input: TSelection) => MaybePromise<boolean>
  • message TMessage

Explanation

With partialCheckAsync you can freely validate the selected input and return true if it is valid or false otherwise. If the input does not match your requirement, you can use message to customize the error message.

The difference to checkAsync is that partialCheckAsync can be executed whenever the selected part of the data is valid, while checkAsync is executed only when the entire dataset is typed. This can be an important advantage when working with forms.

Returns

Examples

The following examples show how partialCheckAsync can be used.

Message details schema

Schema to validate details associated with a message.

import { isSenderInTheGroup } from '~/api';

const MessageDetailsSchema = v.pipeAsync(
  v.object({
    sender: v.object({
      name: v.pipe(v.string(), v.minLength(2), v.maxLength(45)),
      email: v.pipe(v.string(), v.email()),
    }),
    groupId: v.pipe(v.string(), v.uuid()),
    message: v.pipe(v.string(), v.nonEmpty(), v.maxLength(500)),
  }),
  v.forwardAsync(
    v.partialCheckAsync(
      [['sender', 'email'], ['groupId']],
      (input) =>
        isSenderInTheGroup({
          senderEmail: input.sender.email,
          groupId: input.groupId,
        }),
      'The sender is not in the group.'
    ),
    ['sender', 'email']
  )
);

The following APIs can be combined with partialCheckAsync.

Schemas

Utils

Async

Contributors

Thanks to all the contributors who helped make this page better!

  • GitHub profile picture of EltonLobo07
  • GitHub profile picture of fabian-hiller

Partners

Thanks to our partners who support the project ideally and financially.

Sponsors

Thanks to our GitHub sponsors who support the project financially.

  • GitHub profile picture of antfu
  • GitHub profile picture of Thanaen
  • GitHub profile picture of osdiab
  • GitHub profile picture of ruiaraujo012
  • GitHub profile picture of hyunbinseo
  • GitHub profile picture of F0rce
  • GitHub profile picture of fabulousgk
  • GitHub profile picture of jdgamble555
  • GitHub profile picture of isoden
  • GitHub profile picture of nickytonline
  • GitHub profile picture of caegdeveloper
  • GitHub profile picture of luckasnix
  • GitHub profile picture of andrew-3kb
  • GitHub profile picture of dslatkin