From 1ff1e4a8d7971eeed7a5409318b6ce2719703be3 Mon Sep 17 00:00:00 2001 From: Netfan Date: Tue, 12 Nov 2024 13:20:48 +0800 Subject: [PATCH] fix: form enter event handling, fixed #4865 (#4867) --- packages/@core/ui-kit/form-ui/src/vben-use-form.vue | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/@core/ui-kit/form-ui/src/vben-use-form.vue b/packages/@core/ui-kit/form-ui/src/vben-use-form.vue index 8926232f..0401d48e 100644 --- a/packages/@core/ui-kit/form-ui/src/vben-use-form.vue +++ b/packages/@core/ui-kit/form-ui/src/vben-use-form.vue @@ -40,6 +40,13 @@ const handleUpdateCollapsed = (value: boolean) => { }; function handleKeyDownEnter(event: KeyboardEvent) { + if ( + !state.value.submitOnEnter || + !formActionsRef.value || + !formActionsRef.value.handleSubmit + ) { + return; + } // 如果是 textarea 不阻止默认行为,否则会导致无法换行。 // 跳过 textarea 的回车提交处理 if (event.target instanceof HTMLTextAreaElement) { @@ -47,9 +54,6 @@ function handleKeyDownEnter(event: KeyboardEvent) { } event.preventDefault(); - if (!state.value.submitOnEnter || !formActionsRef.value) { - return; - } formActionsRef.value?.handleSubmit?.(); }