Skip to content

Commit

Permalink
Add logic to check if a form should be reset
Browse files Browse the repository at this point in the history
  • Loading branch information
epi-qang2 committed Dec 28, 2023
1 parent e5c4ba7 commit 3ec326b
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/@episerver/forms-react/src/hooks/useElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down

0 comments on commit 3ec326b

Please sign in to comment.