Skip to content

Commit

Permalink
disc. union
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsonav1992 committed Aug 29, 2024
1 parent 4c3256a commit ef4f249
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/Field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,10 @@ export const Field = <
&& !!component
&& checked != undefined;

const fieldValidationOptions: FieldValidationOptions = {
const fieldValidationOptions = {
shouldValidate
, validationEvent
};
} as FieldValidationOptions;

const fieldProps = {
name
Expand Down
46 changes: 25 additions & 21 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,26 +77,30 @@ export type SingleFieldValidator<
, TFieldName extends DeepKeys<TFormValues> = DeepKeys<TFormValues>
> = ( value: DeepValue<TFormValues, TFieldName> ) => Promise<string | Nullish> | string | Nullish;

export type FieldValidationOptions<TShouldValidate = boolean> = {
/**
* Whether to run validation after field value is updated or the field is blurred.
* Setting this prop to `false` will cancel any validation set for the field.
* Granular configuration of the field validation can be set with the `validationEvent`
* prop if set to `true` or not set.
*
* @default true
*/
shouldValidate?: TShouldValidate;
/**
* The field events for which validation should occur. *Only applies if
* `shouldValidate` is set to `true` or not set at all.*
*
* Not setting this prop or setting this prop to `'all'` will run validation on every field
* change or blur event.
*
* @default 'all'
*/
validationEvent?: NoInfer<TShouldValidate> extends true ? never : 'onChange' | 'onBlur' | 'all';
/**
* @param shouldValidate
* Whether to run validation after field value is updated or the field is blurred.
* Setting this prop to `false` will cancel any validation set for the field.
* Granular configuration of the field validation can be set with the `validationEvent`
* prop if set to `true` or not set.
*
* @default true
* -----------------------
* @param validationEvent
* The field events for which validation should occur. *Only applies if
* `shouldValidate` is set to `true` or not set at all.*
*
* Not setting this prop or setting this prop to `'all'` will run validation on every field
* change or blur event.
*
* @default 'all'
*/
export type FieldValidationOptions = {
shouldValidate?: true;
validationEvent?: 'onChange' | 'onBlur' | 'all';
} | {
shouldValidate: false;
validationEvent?: never;
};

////// STORE //////
Expand Down Expand Up @@ -169,7 +173,7 @@ export type FormHandlers<TFormValues extends FormValues> = {
setFieldValue: <
TFieldName extends DeepKeys<TFormValues> = DeepKeys<TFormValues>
, TFieldValue extends DeepValue<TFormValues, TFieldName> = DeepValue<TFormValues, TFieldName>
, TFieldValidationOptions extends FieldValidationOptions = FieldValidationOptions<boolean>
, TFieldValidationOptions extends FieldValidationOptions = FieldValidationOptions
>(
fieldName: TFieldName
, newValue: TFieldValue
Expand Down

0 comments on commit ef4f249

Please sign in to comment.