From 8fb937dd2186beb17583424795926af7fbc1ddc2 Mon Sep 17 00:00:00 2001 From: Timur Ercan Date: Fri, 13 Jan 2023 17:10:15 +0100 Subject: [PATCH] dynamic register data validation --- apps/web/components/signup.tsx | 65 +++++++++++++++++++++++++--------- 1 file changed, 49 insertions(+), 16 deletions(-) diff --git a/apps/web/components/signup.tsx b/apps/web/components/signup.tsx index ff6c726b8..14928a478 100644 --- a/apps/web/components/signup.tsx +++ b/apps/web/components/signup.tsx @@ -16,6 +16,7 @@ export default function Signup() { const methods = useForm({}); const { register, + trigger, formState: { errors, isSubmitting }, } = methods; @@ -67,6 +68,27 @@ export default function Signup() { ); } + function renderFormValidation() { + if (!errors.password && !errors.email) return; + return ( +
+
+
+
+
+

+ {errors.password &&
{errors.password?.message}
} +

+

+ {errors.email &&
{errors.email?.message}
} +

+
+
+
+ ); + } + return ( <>
@@ -93,10 +115,17 @@ export default function Signup() { state-of-the-art document signing for free.

- {renderApiError()} +
+ {renderApiError()} + {renderFormValidation()} +
{ + methods.clearErrors(); + trigger(); + }} className="mt-8 space-y-6" > @@ -121,7 +150,13 @@ export default function Signup() { Password -
- -
-
+ +