UNPKG

@modular-forms/qwik

Version:

The modular and type-safe form library for Qwik

29 lines (28 loc) 820 B
import { $, implicit$FirstArg } from '@builder.io/qwik'; import { getParsedZodSchema } from '../utils'; /** * See {@link zodForm$} */ export function zodFormQrl(schema) { return $(async (values) => { const result = await getParsedZodSchema(schema, values); const formErrors = {}; if (!result.success) { for (const issue of result.error.issues) { const path = issue.path.join('.'); if (!formErrors[path]) { formErrors[path] = issue.message; } } } return formErrors; }); } /** * Creates a validation functions that parses the Zod schema of a form. * * @param schema A Zod schema. * * @returns A validation function. */ export const zodForm$ = implicit$FirstArg(zodFormQrl);