Skip to content

Commit

Permalink
fix: expose missing getFieldError and getFieldErrors on form state
Browse files Browse the repository at this point in the history
  • Loading branch information
lars-berger committed Feb 24, 2025
1 parent 52273df commit 10d14d4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/primitives/create-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import {
unsetDirty,
unsetTouched,
validate,
getFieldError,
getFieldErrors,
} from '../methods';

export type CreateFormOptions<V extends FormValue> = {
Expand Down Expand Up @@ -54,6 +56,8 @@ export function createForm<V extends FormValue>(
get value() {
return formValue();
},
getFieldError: (...args) => getFieldError(formState, ...args),
getFieldErrors: (...args) => getFieldErrors(formState, ...args),
getFieldValue: (...args) => getFieldValue(formState, ...args),
isDirty: (...args) => isDirty(formState, ...args),
isFieldDirty: (...args) => isFieldDirty(formState, ...args),
Expand Down
4 changes: 3 additions & 1 deletion src/types/form-state.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ import type { CreateFormOptions } from '../primitives';

export interface FormState<V extends FormValue> {
value: V;
getFieldError<P extends FieldPath<V>>(fieldPath: P): string | null;
getFieldErrors<P extends FieldPath<V>>(fieldPath: P): string[];
getFieldValue<P extends FieldPath<V>>(fieldPath: P): FieldValue<V, P>;
isDirty(): boolean;
isFieldDirty<P extends FieldPath<V>>(fieldPath: P): boolean;
hasError(): boolean;
hasFieldError<P extends FieldPath<V>>(fieldPath: P): boolean;
isFieldTouched<P extends FieldPath<V>>(fieldPath: P): boolean;
hasError(): boolean;
isTouched(): boolean;
setFieldDirty<P extends FieldPath<V>>(
fieldPath: P,
Expand Down

0 comments on commit 10d14d4

Please sign in to comment.