/** * VeeValidate Form Validation Composable * * Provides convenient setup for VeeValidate with Zod schemas and * German error messages. * * @example * ```vue * * * * ``` */ import { toTypedSchema } from '@vee-validate/zod' import type { z } from 'zod' /** * Configure VeeValidate with Zod schema * * This is a convenience wrapper around toTypedSchema from @vee-validate/zod * that provides type-safe form validation with Zod schemas. * * @param schema - Zod schema for form validation * @returns Typed schema for VeeValidate * * @example * const validationSchema = useZodSchema(checkoutSchema) * const form = useForm({ validationSchema }) */ export function useZodSchema(schema: T) { return toTypedSchema(schema) } /** * Check if a form field has an error * * @param errors - VeeValidate errors object * @param fieldName - Field name to check * @returns true if field has an error */ export function hasFieldError( errors: Record, fieldName: string ): boolean { return !!errors[fieldName] } /** * Get error message for a field * * @param errors - VeeValidate errors object * @param fieldName - Field name to get error for * @returns Error message or empty string */ export function getFieldError( errors: Record, fieldName: string ): string { return errors[fieldName] || '' } /** * Check if form is valid (no errors) * * @param errors - VeeValidate errors object * @returns true if form has no errors */ export function isFormValid(errors: Record): boolean { return Object.keys(errors).length === 0 } /** * Get all error messages as an array * * @param errors - VeeValidate errors object * @returns Array of error messages */ export function getAllErrors(errors: Record): string[] { return Object.values(errors).filter((error): error is string => !!error) }