required
function
Binds a validator to the given path that requires the value to be non-empty.
This function can only be called on any type of path.
In addition to binding a validator, this function adds REQUIRED
property to the field.
API
function required<TValue, TPathKind extends PathKind = PathKind.Root>(
path: FieldPath<TValue, TPathKind>,
config?:
| (BaseValidatorConfig<TValue, TPathKind> & {
emptyPredicate?: ((value: TValue) => boolean) | undefined;
when?: NoInfer<LogicFn<TValue, boolean, TPathKind>> | undefined;
})
| undefined,
): void;
required
void
Binds a validator to the given path that requires the value to be non-empty.
This function can only be called on any type of path.
In addition to binding a validator, this function adds REQUIRED
property to the field.
@paramconfig
(BaseValidatorConfig<TValue, TPathKind> & { emptyPredicate?: ((value: TValue) => boolean) | undefined; when?: NoInfer<LogicFn<TValue, boolean, TPathKind>> | undefined; }) | undefined
Optional, allows providing any of the following options:
message
: A user-facing message for the error.error
: Custom validation error(s) to be used instead of the defaultValidationError.required()
or a function that receives theFieldContext
and returns custom validation error(s).emptyPredicate
: A function that receives the value, and returnstrue
if it is considered empty. By defaultfalse
,''
,null
, andundefined
are considered emptywhen
: A function that receives theFieldContext
and returns true if the field is required
@returns
void
Jump to details