UNPKG

react-swift-form

Version:
96 lines (94 loc) 4.44 kB
import { Dispatch, SetStateAction } from 'react'; import { IError, IFieldMessages, IFormElement, IFormValidator, IFormValues, ILocalFields, ILocalFormValidator, IMainError, IMessages, ITransformers, IValidator, IValidatorError, IValidatorObject } from '../types'; export declare function isValidator(validator?: IValidator | IValidatorObject | Record<string, IValidator | IValidatorObject>): validator is IValidator; export declare function isValidatorObject(validator?: IValidator | IValidatorObject | Record<string, IValidator | IValidatorObject>): validator is IValidatorObject; export declare function isLocalValidator(validator: IFormValidator): validator is ILocalFormValidator; export declare function getNativeErrorKey(validity?: ValidityState): keyof ValidityState | null; interface IGetDataParams { form: HTMLFormElement; names?: string[]; transformers?: ITransformers; values?: IFormValues; } export declare function getData<V extends IFormValues>(params: IGetDataParams): V; export declare function getFieldMessages(validators: IFormValidator[], messages?: IMessages): IFieldMessages; export declare function getFilteredErrors<T>(errors: Record<string, T>, names?: string[]): Record<string, T>; export declare function setMainError(errors: Omit<IError, 'all'>): IMainError | undefined; export declare function getValidatorIds(validators: IFormValidator[], names?: string[]): string[]; export declare function getAllError(nativeErrors: Record<string, string>, validatorErrors: Record<string, IValidatorError>, manualErrors?: Record<string, string | null>): Record<string, string>; interface IGetErrorObjectParams { global?: boolean; ids?: string[]; manualErrors?: Record<string, string | null>; names?: string[]; nativeErrors: Record<string, string>; validatorErrors: Record<string, IValidatorError>; } export declare function getErrorObject(params: IGetErrorObjectParams): IError; export declare function mergeErrors(prevErrors: IError, errors: IError): IError; export declare function hasError(errors: IError): boolean; export declare function getCustomMessage(error: string | null, messages?: IMessages, defaultMessages?: IMessages): string; interface IGetNativeErrorParams { defaultMessages?: IMessages; input: IFormElement; messages?: IMessages; } export declare function getNativeError(params: IGetNativeErrorParams): string; interface IGetNativeErrorsParams { fieldMessages: IFieldMessages; form: HTMLFormElement; } export declare function getNativeErrors(params: IGetNativeErrorsParams): Record<string, string>; interface IGetManualError { errors?: Record<string, string | null>; fieldMessages?: IFieldMessages; form: HTMLFormElement; } export declare function getManualError(params: IGetManualError): Record<string, string | null>; interface IGetValidatorErrorParams { form: HTMLFormElement; transformers?: ITransformers; validators?: IFormValidator[]; values?: IFormValues; } export declare function getValidatorError(params: IGetValidatorErrorParams): Promise<string[]>; interface ISetValidatorErrorParams { defaultMessages?: IMessages; form: HTMLFormElement; validatorResults: string[]; validators: IFormValidator[]; } export declare function setValidatorError(params: ISetValidatorErrorParams): Record<string, IValidatorError>; export declare function focusError(inputs: IFormElement[], main?: IMainError): boolean; interface IDisplayErrorParams { display: boolean; errors: IError; filterLocalErrors?: boolean; focusOnError?: boolean; form: HTMLFormElement; localFields?: ILocalFields; names?: string[]; revalidate: boolean; setErrors: Dispatch<SetStateAction<IError>>; useNativeValidation: boolean; validators: IFormValidator[]; } export declare function displayErrors(params: IDisplayErrorParams): void; interface IValidateFormParams { display: boolean; errors?: Record<string, string | null>; filterLocalErrors?: boolean; focusOnError?: boolean; form: HTMLFormElement; localFields?: ILocalFields; messages?: IMessages; names?: string[]; revalidate: boolean; setErrors: Dispatch<SetStateAction<IError>>; transformers?: ITransformers; useNativeValidation: boolean; validators: IFormValidator[]; values?: IFormValues; } export declare function validateForm(params: IValidateFormParams): Promise<IError>; export {};