maz-ui
Version:
A standalone components library for Vue.Js 3 & Nuxt.Js 3
32 lines (31 loc) • 2.43 kB
TypeScript
import { DeepPartial } from '@maz-ui/utils/ts-helpers/DeepPartial';
import { MaybeRefOrGetter, Ref } from 'vue';
import { BaseFormPayload, ExtractModelKey, FieldsStates, FormSchema, FormValidatorOptions, InferOutputSchemaFormValidator, InferSchemaFormValidator, ValidationIssues } from './useFormValidator/types';
import { scrollToError } from './useFormValidator/dom-events';
export declare function useFormValidator<TSchema extends MaybeRefOrGetter<FormSchema<BaseFormPayload>>>({ schema, defaultValues, model, options }: {
schema: TSchema;
defaultValues?: MaybeRefOrGetter<DeepPartial<InferSchemaFormValidator<TSchema>> | undefined | null>;
model?: Ref<DeepPartial<InferSchemaFormValidator<TSchema>> | undefined | null>;
options?: FormValidatorOptions<InferSchemaFormValidator<TSchema>>;
}): {
identifier: string | symbol;
isDirty: import('vue').ComputedRef<boolean>;
isSubmitting: Ref<boolean, boolean>;
isSubmitted: Ref<boolean, boolean>;
isValid: import('vue').ComputedRef<boolean>;
errors: import('vue').ComputedRef<Record<ExtractModelKey<FormSchema<InferSchemaFormValidator<TSchema>>>, ValidationIssues>>;
model: Ref<InferSchemaFormValidator<TSchema>, InferSchemaFormValidator<TSchema>>;
fieldsStates: Ref<FieldsStates<InferSchemaFormValidator<TSchema>, ExtractModelKey<FormSchema<InferSchemaFormValidator<TSchema>>>>, FieldsStates<InferSchemaFormValidator<TSchema>, ExtractModelKey<FormSchema<InferSchemaFormValidator<TSchema>>>>>;
validateForm: (setErrors?: boolean) => Promise<void[]>;
scrollToError: typeof scrollToError;
resetForm: () => void;
handleSubmit: <Func extends (model: InferOutputSchemaFormValidator<TSchema>) => Promise<Awaited<ReturnType<Func>>> | ReturnType<Func>>(successCallback: Func, enableScrollOrSelector?: FormValidatorOptions["scrollToError"], options?: {
onError?: (payload: {
model: InferSchemaFormValidator<TSchema>;
errorMessages: Record<ExtractModelKey<FormSchema<InferSchemaFormValidator<TSchema>>>, string | undefined>;
errors: Record<ExtractModelKey<FormSchema<InferSchemaFormValidator<TSchema>>>, ValidationIssues>;
}) => void;
resetOnSuccess?: boolean;
}) => (event?: Event) => Promise<ReturnType<Func> | undefined>;
errorMessages: import('vue').ComputedRef<Record<ExtractModelKey<FormSchema<InferSchemaFormValidator<TSchema>>>, string | undefined>>;
};