Skip to content

Commit

Permalink
fix: form submission not appropriate (#5126)
Browse files Browse the repository at this point in the history
  • Loading branch information
mynetfan authored Dec 13, 2024
1 parent cbca9ff commit 1d3729a
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 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,9 @@ import type { ExtendedFormApi, VbenFormProps } from './types';
import { useForwardPriorityValues } from '@vben-core/composables';
// import { isFunction } from '@vben-core/shared/utils';
import { toRaw, useTemplateRef, watch } from 'vue';
import { nextTick, onMounted, useTemplateRef, watch } from 'vue';
import { cloneDeep } from '@vben-core/shared/utils';
import { useDebounceFn } from '@vueuse/core';
Expand Down Expand Up @@ -59,14 +61,16 @@ function handleKeyDownEnter(event: KeyboardEvent) {
formActionsRef.value?.handleSubmit?.();
}
watch(
() => form.values,
useDebounceFn(() => {
forward.value.handleValuesChange?.(toRaw(form.values));
state.value.submitOnChange && props.formApi?.submitForm();
}, 300),
{ deep: true },
);
const handleValuesChangeDebounced = useDebounceFn((newVal) => {
forward.value.handleValuesChange?.(cloneDeep(newVal));
state.value.submitOnChange && formActionsRef.value?.handleSubmit?.();
}, 300);
onMounted(async () => {
// 只在挂载后开始监听,form.values会有一个初始化的过程
await nextTick();
watch(() => form.values, handleValuesChangeDebounced, { deep: true });
});
</script>

<template>
Expand Down

0 comments on commit 1d3729a

Please sign in to comment.