From ff5c80252f49b013a0a0cfd05050a7cade91dc2f Mon Sep 17 00:00:00 2001 From: Parwat Kunwar Date: Fri, 31 Jan 2025 02:57:02 -0400 Subject: [PATCH] Handle blur event to track password validation (#192) - Shows validation when the focus is out. - Creates an error if validation fails stopping to send the api request. --- Client/src/app/documents/components/CreateLink.tsx | 4 +++- .../src/app/documents/components/SharingOptionsAccordion.tsx | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Client/src/app/documents/components/CreateLink.tsx b/Client/src/app/documents/components/CreateLink.tsx index c58ec7e..a7660d5 100644 --- a/Client/src/app/documents/components/CreateLink.tsx +++ b/Client/src/app/documents/components/CreateLink.tsx @@ -53,7 +53,7 @@ export default function CreateLink({ onClose, open, documentId }: CreateLinkProp requiredUserDetailsOption: 1, }; - const { values, setValues, validateAll, getError } = useValidatedFormData({ + const { values, setValues, validateAll, getError, handleBlur } = useValidatedFormData({ initialValues: initialFormValues, validationRules }); @@ -144,6 +144,7 @@ export default function CreateLink({ onClose, open, documentId }: CreateLinkProp const { loading, handleSubmit, error, toast } = useFormSubmission({ onSubmit: async () => { const hasError = validateAll(); + if (hasError) { throw new Error('Please correct any errors before generating a link.'); } @@ -232,6 +233,7 @@ export default function CreateLink({ onClose, open, documentId }: CreateLinkProp string; handleExpirationChange: (event: React.ChangeEvent) => void; + handleBlur: (event: React.FocusEvent) => void; } const SharingOptionsAccordion = ({ @@ -25,6 +26,7 @@ const SharingOptionsAccordion = ({ isPasswordVisible, setIsPasswordVisible, expirationType, + handleBlur, handleExpirationChange, }: SharingOptionsAccordionProps) => { return ( @@ -77,7 +79,6 @@ const SharingOptionsAccordion = ({ mb={4} ml={13}>