mirror of
https://github.com/vbenjs/vue-vben-admin.git
synced 2025-02-02 18:28:40 +08:00
fix: form auto submit no effect when showDefaultActions is false (#5163)
This commit is contained in:
parent
4fe44611d3
commit
181e38733c
@ -6,7 +6,7 @@ import type { ExtendedFormApi, VbenFormProps } from './types';
|
|||||||
import { useForwardPriorityValues } from '@vben-core/composables';
|
import { useForwardPriorityValues } from '@vben-core/composables';
|
||||||
// import { isFunction } from '@vben-core/shared/utils';
|
// 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';
|
import { cloneDeep } from '@vben-core/shared/utils';
|
||||||
|
|
||||||
@ -27,8 +27,6 @@ interface Props extends VbenFormProps {
|
|||||||
|
|
||||||
const props = defineProps<Props>();
|
const props = defineProps<Props>();
|
||||||
|
|
||||||
const formActionsRef = useTemplateRef<typeof FormActions>('formActionsRef');
|
|
||||||
|
|
||||||
const state = props.formApi?.useStore?.();
|
const state = props.formApi?.useStore?.();
|
||||||
|
|
||||||
const forward = useForwardPriorityValues(props, state);
|
const forward = useForwardPriorityValues(props, state);
|
||||||
@ -44,11 +42,7 @@ const handleUpdateCollapsed = (value: boolean) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function handleKeyDownEnter(event: KeyboardEvent) {
|
function handleKeyDownEnter(event: KeyboardEvent) {
|
||||||
if (
|
if (!state.value.submitOnEnter || !forward.value.formApi?.isMounted) {
|
||||||
!state.value.submitOnEnter ||
|
|
||||||
!formActionsRef.value ||
|
|
||||||
!formActionsRef.value.handleSubmit
|
|
||||||
) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 如果是 textarea 不阻止默认行为,否则会导致无法换行。
|
// 如果是 textarea 不阻止默认行为,否则会导致无法换行。
|
||||||
@ -58,12 +52,12 @@ function handleKeyDownEnter(event: KeyboardEvent) {
|
|||||||
}
|
}
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
formActionsRef.value?.handleSubmit?.();
|
forward.value.formApi.validateAndSubmitForm();
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleValuesChangeDebounced = useDebounceFn((newVal) => {
|
const handleValuesChangeDebounced = useDebounceFn((newVal) => {
|
||||||
forward.value.handleValuesChange?.(cloneDeep(newVal));
|
forward.value.handleValuesChange?.(cloneDeep(newVal));
|
||||||
state.value.submitOnChange && formActionsRef.value?.handleSubmit?.();
|
state.value.submitOnChange && forward.value.formApi?.validateAndSubmitForm();
|
||||||
}, 300);
|
}, 300);
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
@ -94,7 +88,6 @@ onMounted(async () => {
|
|||||||
<slot v-bind="slotProps">
|
<slot v-bind="slotProps">
|
||||||
<FormActions
|
<FormActions
|
||||||
v-if="forward.showDefaultActions"
|
v-if="forward.showDefaultActions"
|
||||||
ref="formActionsRef"
|
|
||||||
:model-value="state.collapsed"
|
:model-value="state.collapsed"
|
||||||
@update:model-value="handleUpdateCollapsed"
|
@update:model-value="handleUpdateCollapsed"
|
||||||
>
|
>
|
||||||
|
Loading…
Reference in New Issue
Block a user