From e9b02c61deaec766bde6bf8494e7b724946f05e3 Mon Sep 17 00:00:00 2001 From: Stef Lewandowski Date: Tue, 15 Oct 2024 12:11:09 +0100 Subject: [PATCH] fix: add fallback if requestSubmit is not available (#227) --- apps/nextjs/src/lib/hooks/use-enter-submit.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/apps/nextjs/src/lib/hooks/use-enter-submit.tsx b/apps/nextjs/src/lib/hooks/use-enter-submit.tsx index 9ea937c9e..8afc84b5d 100644 --- a/apps/nextjs/src/lib/hooks/use-enter-submit.tsx +++ b/apps/nextjs/src/lib/hooks/use-enter-submit.tsx @@ -15,7 +15,13 @@ export function useEnterSubmit(): { !event.nativeEvent.isComposing ) { try { - formRef.current?.requestSubmit(); + if (formRef.current?.requestSubmit) { + formRef.current.requestSubmit(); + } else if (formRef.current?.submit) { + formRef.current.submit(); + } else { + throw new Error("Form submission not supported"); + } } catch (error) { console.error("Failed to submit form:", error); }