Commit 94bf854dd98f37ffb39e9086c565a0610c250205
1 parent
1db72c8f
fix: fix form submit error
Showing
3 changed files
with
10 additions
and
6 deletions
src/components/Form/src/BasicForm.vue
@@ -53,8 +53,8 @@ | @@ -53,8 +53,8 @@ | ||
53 | const formModel = reactive({}); | 53 | const formModel = reactive({}); |
54 | 54 | ||
55 | const actionState = reactive({ | 55 | const actionState = reactive({ |
56 | - resetAction: {}, | ||
57 | - submitAction: {}, | 56 | + resetAction: () => {}, |
57 | + submitAction: () => {}, | ||
58 | }); | 58 | }); |
59 | 59 | ||
60 | const advanceState = reactive<AdvanceState>({ | 60 | const advanceState = reactive<AdvanceState>({ |
src/components/Form/src/FormItem.tsx
@@ -150,7 +150,11 @@ export default defineComponent({ | @@ -150,7 +150,11 @@ export default defineComponent({ | ||
150 | function handleValue(component: ComponentType, field: string) { | 150 | function handleValue(component: ComponentType, field: string) { |
151 | const val = (props.formModel as any)[field]; | 151 | const val = (props.formModel as any)[field]; |
152 | if (['Input', 'InputPassword', 'InputSearch', 'InputTextArea'].includes(component)) { | 152 | if (['Input', 'InputPassword', 'InputSearch', 'InputTextArea'].includes(component)) { |
153 | - return isNumber(val) && val ? `${val}` : val; | 153 | + if (val && isNumber(val)) { |
154 | + (props.formModel as any)[field] = `${val}`; | ||
155 | + return `${val}`; | ||
156 | + } | ||
157 | + return val; | ||
154 | } | 158 | } |
155 | return val; | 159 | return val; |
156 | } | 160 | } |
src/components/Form/src/hooks/useFormAction.ts
@@ -43,7 +43,7 @@ export function useFormAction({ | @@ -43,7 +43,7 @@ export function useFormAction({ | ||
43 | Object.keys(formModel).forEach((key) => { | 43 | Object.keys(formModel).forEach((key) => { |
44 | (formModel as any)[key] = defaultValueRef.value[key]; | 44 | (formModel as any)[key] = defaultValueRef.value[key]; |
45 | }); | 45 | }); |
46 | - formEl.clearValidate(); | 46 | + clearValidate(); |
47 | emit('reset', toRaw(formModel)); | 47 | emit('reset', toRaw(formModel)); |
48 | // return values; | 48 | // return values; |
49 | submitOnReset && handleSubmit(); | 49 | submitOnReset && handleSubmit(); |
@@ -187,7 +187,7 @@ export function useFormAction({ | @@ -187,7 +187,7 @@ export function useFormAction({ | ||
187 | return formElRef.value.validate(nameList); | 187 | return formElRef.value.validate(nameList); |
188 | } | 188 | } |
189 | 189 | ||
190 | - function clearValidate(name: string | string[]) { | 190 | + function clearValidate(name?: string | string[]) { |
191 | if (!formElRef.value) return; | 191 | if (!formElRef.value) return; |
192 | formElRef.value.clearValidate(name); | 192 | formElRef.value.clearValidate(name); |
193 | } | 193 | } |
@@ -205,7 +205,7 @@ export function useFormAction({ | @@ -205,7 +205,7 @@ export function useFormAction({ | ||
205 | const formEl = unref(formElRef); | 205 | const formEl = unref(formElRef); |
206 | if (!formEl) return; | 206 | if (!formEl) return; |
207 | try { | 207 | try { |
208 | - const values = await formEl.validate(); | 208 | + const values = await validate(); |
209 | const res = handleFormValues(values); | 209 | const res = handleFormValues(values); |
210 | emit('submit', res); | 210 | emit('submit', res); |
211 | } catch (error) {} | 211 | } catch (error) {} |