Skip to main content

Types

IError

interface IError {
all: Record<string, string>;
global: Record<string, IValidatorError>;
main?: IMainError;
manual: Record<string, string | null>;
native: Record<string, string>;
validator: Record<string, IValidatorError>;
}

IFormContext

interface IFormContext {
errors: IError;
form: RefObject<HTMLFormElement>;
messages?: IMessages;
mode: IFormMode;
onChange: IOnChangeHandler;
onError: IOnErrorHandler;
onReset: IOnResetHandler;
onSubmit: IOnSubmitHandler;
register: IRegister;
reset: IFormReset;
revalidateMode: IFormRevalidateMode;
subscribe: ISubscribe;
unregister: IUnregister;
useNativeValidation: boolean;
validate: IFormValidate;
watch: IWatch;
}

IFormReset

type IFormReset = (resetValues?: Record<string, unknown> | null) => void;

IMainError

interface IMainError {
error: string;
global: boolean;
id: string;
names: string[];
}

IOnChangeHandler

type IOnChangeHandler = <V, T extends unknown[] = unknown[]>(params?: {
callback?: ((value: V, ...args: T) => void) | null;
getError?: ((value: V, ...args: T) => string | null) | null;
name?: string;
transformer?: ((value: unknown) => V) | null;
}) => (value: unknown, ...args: T) => void;

IOnErrorHandler

type IOnErrorHandler = (name: string) => (error: string | null) => void;

IOnResetHandler

type IOnResetHandler = (
callback?: IResetHandler,
) => (event: FormEvent<HTMLFormElement>) => void;

IOnSubmitHandler

type IOnSubmitHandler = (
validCallback?: ISubmitHandler,
invalidCallback?: ISubmitErrorHandler,
) => (event: FormEvent<HTMLFormElement>) => void;

IResetHandler

type IResetHandler = (
event: FormEvent<HTMLFormElement>,
values: Record<string, unknown>,
) => Record<string, unknown> | null | void;

ISubmitHandler

type ISubmitHandler = (
event: FormEvent<HTMLFormElement>,
values: Record<string, unknown>,
reset: IFormReset,
) => void;

ISubmitErrorHandler

type ISubmitErrorHandler = (
event: FormEvent<HTMLFormElement>,
error: IError,
reset: IFormReset,
) => void;

ISubscribe

type ISubscribe = (
subscriber: ISubscriber,
names?: string[] | string,
) => IUnSubscribe;

ISubscriber

type ISubscriber = (params: ISubscriberParams) => void;

ISubscriberParams

interface ISubscriberParams {
form: HTMLFormElement | null;
names?: string[];
prevValues: IFormValues;
states: IFormStates;
values: IFormValues;
}

IValidator

type IValidator = (values: Record<string, unknown>, names: string[]) => string;

IValidatorError

interface IValidatorError {
error: string;
global: boolean;
names: string[];
}

IValidatorObject

interface IValidatorObject {
names: string[];
validator: IValidator;
}

IWatch

type IWatch = <V extends Record<string, unknown>>(
callback: (values: V) => void,
names?: string[] | string,
) => IUnSubscribe;