fix: form submission not appropriate (#5126)

dev-v5
Netfan 2024-12-13 10:56:24 +08:00 committed by GitHub
parent cbca9ffd95
commit 1d3729aa24
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 13 additions and 9 deletions

View File

@ -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';
@ -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>