From 302a53c4b41e4383eb53ffda0c57d7c51ece48da Mon Sep 17 00:00:00 2001 From: johniFirst Date: Fri, 27 Sep 2024 10:57:38 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=8C=E5=96=84form=E7=BB=84?= =?UTF-8?q?=E4=BB=B6validate=E5=87=BD=E6=95=B0=E7=9A=84=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E5=80=BC=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/packages/__VUE/form/__tests__/index.spec.tsx | 8 ++++---- src/packages/__VUE/form/form.vue | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/packages/__VUE/form/__tests__/index.spec.tsx b/src/packages/__VUE/form/__tests__/index.spec.tsx index 3563685f99..244e00e21d 100644 --- a/src/packages/__VUE/form/__tests__/index.spec.tsx +++ b/src/packages/__VUE/form/__tests__/index.spec.tsx @@ -1,6 +1,6 @@ import { DOMWrapper, mount } from '@vue/test-utils' import { nextTick, ref } from 'vue' -import { Form, FormItem, Button, Textarea, Switch, Checkbox, Rate, InputNumber, Range, Uploader } from '@nutui/nutui' +import { Form, FormItem, Button, Textarea, Switch, Checkbox, Rate, InputNumber, Range, Uploader, FormInstance } from '@nutui/nutui' test('base Form', () => { const wrapper = mount(() => { @@ -47,9 +47,9 @@ test('base Dynamic Form', async () => { value: '' }) }) - const formRef = ref() + const formRef = ref() const submit = () => { - formRef.value.validate().then(({ valid }: any) => { + formRef.value!.validate().then(({ valid }) => { if (valid) { // console.log('success', dynamicForm); } else { @@ -58,7 +58,7 @@ test('base Dynamic Form', async () => { }) } const reset = () => { - formRef.value.reset() + formRef.value!.reset() } const remove = () => { val.value.tels.pop() diff --git a/src/packages/__VUE/form/form.vue b/src/packages/__VUE/form/form.vue index 48181fa450..96c14db113 100644 --- a/src/packages/__VUE/form/form.vue +++ b/src/packages/__VUE/form/form.vue @@ -143,7 +143,7 @@ const checkRule = async (item: FormRule): Promise => * @param customProp 指定校验,用于用户自定义场景时触发,例如 blur、change 事件 * @returns */ -const validate = (customProp = '') => { +const validate = (customProp = ''): Promise<{ valid: boolean, errors: any[] }> => { return new Promise((resolve, reject) => { try { const task = getTaskFromChildren()