Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: form auto submit no effect when showDefaultActions is false #5163

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 4 additions & 11 deletions packages/@core/ui-kit/form-ui/src/vben-use-form.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { ExtendedFormApi, VbenFormProps } from './types';
import { useForwardPriorityValues } from '@vben-core/composables';
// import { isFunction } from '@vben-core/shared/utils';

import { nextTick, onMounted, useTemplateRef, watch } from 'vue';
import { nextTick, onMounted, watch } from 'vue';

import { cloneDeep } from '@vben-core/shared/utils';

Expand All @@ -27,8 +27,6 @@ interface Props extends VbenFormProps {

const props = defineProps<Props>();

const formActionsRef = useTemplateRef<typeof FormActions>('formActionsRef');

const state = props.formApi?.useStore?.();

const forward = useForwardPriorityValues(props, state);
Expand All @@ -44,11 +42,7 @@ const handleUpdateCollapsed = (value: boolean) => {
};

function handleKeyDownEnter(event: KeyboardEvent) {
if (
!state.value.submitOnEnter ||
!formActionsRef.value ||
!formActionsRef.value.handleSubmit
) {
if (!state.value.submitOnEnter || !forward.value.formApi?.isMounted) {
return;
}
// 如果是 textarea 不阻止默认行为,否则会导致无法换行。
Expand All @@ -58,12 +52,12 @@ function handleKeyDownEnter(event: KeyboardEvent) {
}
event.preventDefault();

formActionsRef.value?.handleSubmit?.();
forward.value.formApi.validateAndSubmitForm();
}

const handleValuesChangeDebounced = useDebounceFn((newVal) => {
forward.value.handleValuesChange?.(cloneDeep(newVal));
state.value.submitOnChange && formActionsRef.value?.handleSubmit?.();
state.value.submitOnChange && forward.value.formApi?.validateAndSubmitForm();
}, 300);

onMounted(async () => {
Expand Down Expand Up @@ -94,7 +88,6 @@ onMounted(async () => {
<slot v-bind="slotProps">
<FormActions
v-if="forward.showDefaultActions"
ref="formActionsRef"
:model-value="state.collapsed"
@update:model-value="handleUpdateCollapsed"
>
Expand Down
Loading