From f29b99cdf852f8a0bafb32722e9cd384230cc4a8 Mon Sep 17 00:00:00 2001 From: basseche Date: Fri, 3 Jan 2025 15:32:13 +0100 Subject: [PATCH] Fix : UniqueNameInput, trigger validation after clearing error, used to wait for asynchronous function call response --- .../inputs/reactHookForm/text/UniqueNameInput.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/components/inputs/reactHookForm/text/UniqueNameInput.tsx b/src/components/inputs/reactHookForm/text/UniqueNameInput.tsx index a1a13df5..2357871e 100644 --- a/src/components/inputs/reactHookForm/text/UniqueNameInput.tsx +++ b/src/components/inputs/reactHookForm/text/UniqueNameInput.tsx @@ -60,6 +60,7 @@ export function UniqueNameInput({ const { setError, clearErrors, + trigger, formState: { errors }, } = useFormContext(); @@ -89,10 +90,14 @@ export function UniqueNameInput({ }) .finally(() => { clearErrors('root.isValidating'); + /* force form to validate, otherwise form + will remain invalid (setError('root.isValidating') invalid form and clearErrors does not affect form isValid state : + see documentation : https://react-hook-form.com/docs/useform/clearerrors) */ + trigger('root.isValidating'); }); } }, - [setError, clearErrors, name, elementType, elementExists, directory] + [setError, clearErrors, name, elementType, elementExists, directory, trigger] ); const debouncedHandleCheckName = useDebounce(handleCheckName, 700);