Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ValidationModeFlags Type #11144

Merged
merged 2 commits into from
Nov 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion reports/api-extractor.md
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,15 @@ export type ValidateResult = Message | Message[] | boolean | undefined;
// @public (undocumented)
export type ValidationMode = typeof VALIDATION_MODE;

// @public (undocumented)
export type ValidationModeFlags = {
isOnSubmit: boolean;
isOnBlur: boolean;
isOnChange: boolean;
isOnAll: boolean;
isOnTouch: boolean;
};

// @public (undocumented)
export type ValidationRule<TValidationValue extends ValidationValue = ValidationValue> = TValidationValue | ValidationValueMessage<TValidationValue>;

Expand All @@ -852,7 +861,7 @@ export type WatchObserver<TFieldValues extends FieldValues> = (value: DeepPartia

// Warnings were encountered during analysis:
//
// src/types/form.ts:431:3 - (ae-forgotten-export) The symbol "Subscription" needs to be exported by the entry point index.d.ts
// src/types/form.ts:439:3 - (ae-forgotten-export) The symbol "Subscription" needs to be exported by the entry point index.d.ts

// (No @packageDocumentation comment for this package)

Expand Down
12 changes: 2 additions & 10 deletions src/logic/getValidationModes.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
import { VALIDATION_MODE } from '../constants';
import { Mode } from '../types';
import { Mode, ValidationModeFlags } from '../types';

export default (
mode?: Mode,
): {
isOnSubmit: boolean;
isOnBlur: boolean;
isOnChange: boolean;
isOnAll: boolean;
isOnTouch: boolean;
} => ({
export default (mode?: Mode): ValidationModeFlags => ({
isOnSubmit: !mode || mode === VALIDATION_MODE.onSubmit,
isOnBlur: mode === VALIDATION_MODE.onBlur,
isOnChange: mode === VALIDATION_MODE.onChange,
Expand Down
10 changes: 3 additions & 7 deletions src/logic/skipValidation.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { ValidationModeFlags } from '../types';

export default (
isBlurEvent: boolean,
isTouched: boolean,
Expand All @@ -6,13 +8,7 @@ export default (
isOnBlur: boolean;
isOnChange: boolean;
},
mode: Partial<{
isOnSubmit: boolean;
isOnBlur: boolean;
isOnChange: boolean;
isOnTouch: boolean;
isOnAll: boolean;
}>,
mode: Partial<ValidationModeFlags>,
) => {
if (mode.isOnAll) {
return false;
Expand Down
8 changes: 8 additions & 0 deletions src/types/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ export type ValidationMode = typeof VALIDATION_MODE;

export type Mode = keyof ValidationMode;

export type ValidationModeFlags = {
isOnSubmit: boolean;
isOnBlur: boolean;
isOnChange: boolean;
isOnAll: boolean;
isOnTouch: boolean;
};

export type CriteriaMode = 'firstError' | 'all';

export type SubmitHandler<TFieldValues extends FieldValues> = (
Expand Down