From 3ec326bc10d14d915f34e5a4ea59e4517e636034 Mon Sep 17 00:00:00 2001 From: "EP\\qang2" Date: Thu, 28 Dec 2023 11:41:23 +0700 Subject: [PATCH] Add logic to check if a form should be reset --- src/@episerver/forms-react/src/hooks/useElement.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/@episerver/forms-react/src/hooks/useElement.ts b/src/@episerver/forms-react/src/hooks/useElement.ts index 5685bc2..8ada695 100644 --- a/src/@episerver/forms-react/src/hooks/useElement.ts +++ b/src/@episerver/forms-react/src/hooks/useElement.ts @@ -156,9 +156,18 @@ export const useElement = (element: FormElementBase) => { dispatchFuncs.updateValidation(element.key, formValidation.validate(value)); } + const shouldResetForm = (resetConfirmationMessage: string) => { + if (isNullOrEmpty(resetConfirmationMessage)) { + return true; + } + + const userConfirmed = confirm(htmlDecodeEntities(resetConfirmationMessage)); + return userConfirmed; + }; + const handleReset = () => { const form = formContext?.formContainer ?? {} as FormContainer - if (confirm(htmlDecodeEntities(form.properties.resetConfirmationMessage))) { + if (shouldResetForm(form.properties.resetConfirmationMessage)) { dispatchFuncs.resetForm(form); } }