Skip to content

Commit

Permalink
fix: fix form submit error
Browse files Browse the repository at this point in the history
  • Loading branch information
anncwb committed Nov 5, 2020
1 parent 1db72c8 commit 94bf854
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/components/Form/src/BasicForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@
const formModel = reactive({});
const actionState = reactive({
resetAction: {},
submitAction: {},
resetAction: () => {},
submitAction: () => {},
});
const advanceState = reactive<AdvanceState>({
Expand Down
6 changes: 5 additions & 1 deletion src/components/Form/src/FormItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,11 @@ export default defineComponent({
function handleValue(component: ComponentType, field: string) {
const val = (props.formModel as any)[field];
if (['Input', 'InputPassword', 'InputSearch', 'InputTextArea'].includes(component)) {
return isNumber(val) && val ? `${val}` : val;
if (val && isNumber(val)) {
(props.formModel as any)[field] = `${val}`;
return `${val}`;
}
return val;
}
return val;
}
Expand Down
6 changes: 3 additions & 3 deletions src/components/Form/src/hooks/useFormAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function useFormAction({
Object.keys(formModel).forEach((key) => {
(formModel as any)[key] = defaultValueRef.value[key];
});
formEl.clearValidate();
clearValidate();
emit('reset', toRaw(formModel));
// return values;
submitOnReset && handleSubmit();
Expand Down Expand Up @@ -187,7 +187,7 @@ export function useFormAction({
return formElRef.value.validate(nameList);
}

function clearValidate(name: string | string[]) {
function clearValidate(name?: string | string[]) {
if (!formElRef.value) return;
formElRef.value.clearValidate(name);
}
Expand All @@ -205,7 +205,7 @@ export function useFormAction({
const formEl = unref(formElRef);
if (!formEl) return;
try {
const values = await formEl.validate();
const values = await validate();
const res = handleFormValues(values);
emit('submit', res);
} catch (error) {}
Expand Down

0 comments on commit 94bf854

Please sign in to comment.