From fb1ea0a6ea380354097c30b71d09310af4f84018 Mon Sep 17 00:00:00 2001 From: Genki Takiuchi Date: Tue, 20 Aug 2024 23:34:02 +0900 Subject: [PATCH] Added an optional custom validater to valiForm$ --- packages/qwik/src/adapters/valiForm$.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/qwik/src/adapters/valiForm$.ts b/packages/qwik/src/adapters/valiForm$.ts index 608260d..2b4bc51 100644 --- a/packages/qwik/src/adapters/valiForm$.ts +++ b/packages/qwik/src/adapters/valiForm$.ts @@ -17,7 +17,13 @@ import type { * See {@link valiForm$} */ export function valiFormQrl( - schema: QRL> + schema: QRL>, + validater$?: QRL< + ( + values: PartialValues, + errors: FormErrors + ) => Promise + > ): QRL> { return $(async (values: PartialValues) => { const resolvedSchema = await schema.resolve(); @@ -32,6 +38,10 @@ export function valiFormQrl( formErrors[getDotPath(issue)!] = issue.message; } } + if (validater$) { + const varidater = await validater$.resolve(); + await varidater(values, formErrors); + } return formErrors as FormErrors; }); }