unika-components
Version:
Unika Vue3 components library
39 lines (38 loc) • 1.17 kB
TypeScript
import { Ref } from 'vue';
export interface FormField {
id: string | number;
name: string;
type: string;
valueRef: Ref<any>;
required?: boolean;
validate?: () => boolean | Promise<boolean>;
reset?: () => void;
}
export interface FormContext {
registerField(field: FormField): void;
unregisterField(id: string | number): void;
validate(): Promise<{
isValid: boolean;
errors: Record<string, string>;
}>;
getFormData(): Record<string, any>;
resetForm(): void;
submitForm(sceneId: string, host: string): Promise<{
success: boolean;
message?: string;
}>;
getFieldErrors(): Record<string, string>;
}
export declare function createFormContext(options?: {
autoReset?: boolean;
onSubmit?: (data: Record<string, any>) => Promise<void> | void;
}): FormContext;
export declare function useForm(): FormContext | null;
export declare function useFormField(field: Omit<FormField, 'reset'>): {
validate: () => Promise<boolean>;
} | {
validate: () => Promise<{
isValid: boolean;
errors: Record<string, string>;
}>;
};