Skip to content

Commit

Permalink
feat: form 增加beforeSubmit,和afterSubmit配置
Browse files Browse the repository at this point in the history
  • Loading branch information
greper committed Jan 7, 2022
1 parent 4d49413 commit aadc77d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
10 changes: 10 additions & 0 deletions docs/zh/api/crud-options/form.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,13 @@
* 说明: 提交表单时执行的方法(独立使用表单时,通过`formRef.submit()`可触发此方法)
* 类型:async Function(context)
* 默认:默认无需配置,通过`useCrud`自动生成


## beforeSubmit
* 说明: 表单提交前触发,返回false则中止提交
* 类型:async Function(context)


## doSubmit
* 说明: 表单提交后触发
* 类型:async Function(context)
13 changes: 11 additions & 2 deletions packages/fast-crud/src/components/crud/fs-form.vue
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,16 @@ export default {
type: Function,
default: undefined
},
/**
* 表单提交前处理(async)
*/
beforeSubmit: {
type: Function,
default: undefined
},
/**
* 表单提交后处理(async)
*/
afterSubmit: {
type: Function,
default: undefined
Expand Down Expand Up @@ -380,14 +386,17 @@ export default {
});
if (props.beforeSubmit) {
props.beforeSubmit(submitScope);
const ret = await props.beforeSubmit(submitScope);
if(ret === false){
return;
}
}
if (props.doSubmit) {
await props.doSubmit(submitScope);
}
ctx.emit("submit", submitScope);
if (props.afterSubmit) {
props.afterSubmit(submitScope);
await props.afterSubmit(submitScope);
}
}
Expand Down

0 comments on commit aadc77d

Please sign in to comment.