Skip to content

Commit

Permalink
表单校验有问题修复,必填的form的validate校验反过来了 #issues/4189
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangdaiscott committed Nov 8, 2022
1 parent d9eaf06 commit 7957147
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/hooks/component/useFormItem.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { UnwrapRef, Ref, WritableComputedRef, DeepReadonly } from 'vue';
import { reactive, readonly, computed, getCurrentInstance, watchEffect, unref, nextTick, toRaw } from 'vue';
import {Form} from "ant-design-vue";

import { isEqual } from 'lodash-es';
export function useRuleFormItem<T extends Recordable, K extends keyof T, V = UnwrapRef<T[K]>>(
Expand All @@ -11,6 +12,7 @@ export function useRuleFormItem<T extends Recordable, K extends keyof T, V = Unw
export function useRuleFormItem<T extends Recordable>(props: T, key: keyof T = 'value', changeEvent = 'change', emitData?: Ref<any[]>) {
const instance = getCurrentInstance();
const emit = instance?.emit;
const formItemContext = Form.useInjectFormItemContext();

const innerState = reactive({
value: props[key],
Expand All @@ -37,6 +39,9 @@ export function useRuleFormItem<T extends Recordable>(props: T, key: keyof T = '
innerState.value = value as T[keyof T];
nextTick(() => {
emit?.(changeEvent, value, ...(toRaw(unref(emitData)) || []));
// https://antdv.com/docs/vue/migration-v3-cn
// antDv3升级后需要调用这个方法更新校验的值
nextTick(() => formItemContext.onFieldChange());
});
},
});
Expand Down

0 comments on commit 7957147

Please sign in to comment.