mirror of
https://gitee.com/baidu/amis.git
synced 2024-12-03 12:29:24 +08:00
feat: for支持pureSubmit事件
This commit is contained in:
parent
bdb310d201
commit
7f48846bfe
@ -1458,6 +1458,7 @@ Form 支持轮询初始化接口,步骤如下:
|
|||||||
| formItemValidateError | `event.data: object` 当前表单数据 | 表单项校验失败时触发 |
|
| formItemValidateError | `event.data: object` 当前表单数据 | 表单项校验失败时触发 |
|
||||||
| validateSucc | `event.data: object` 当前表单数据 | 表单校验成功时触发 |
|
| validateSucc | `event.data: object` 当前表单数据 | 表单校验成功时触发 |
|
||||||
| validateError | `event.data: object` 当前表单数据 | 表单校验失败时触发 |
|
| validateError | `event.data: object` 当前表单数据 | 表单校验失败时触发 |
|
||||||
|
| pureSubmit | `event.data: object` 当前表单数据 | 表单提交后触发,配置了该事件将不会触发表单提交时默认的校验、提交到api或者target等行为,所有行为需要自己配置 |
|
||||||
| submitSucc | `event.data.result: object` api 远程请求成功后返回的结果数据 | 提交成功时触发 |
|
| submitSucc | `event.data.result: object` api 远程请求成功后返回的结果数据 | 提交成功时触发 |
|
||||||
| submitFail | `event.data.error: object` api 远程请求失败后返回的错误信息 | 提交失败时触发 |
|
| submitFail | `event.data.error: object` api 远程请求失败后返回的错误信息 | 提交失败时触发 |
|
||||||
|
|
||||||
|
@ -276,6 +276,43 @@ export default {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'form',
|
||||||
|
debug: true,
|
||||||
|
api: '/api/mock2/form/saveForm',
|
||||||
|
title: "表单:配置pureSubmit事件后将不会触发表单提交时默认的校验、提交到api或者target等行为,所有行为需要自己配置",
|
||||||
|
body: [
|
||||||
|
{
|
||||||
|
type: 'input-text',
|
||||||
|
name: 'name',
|
||||||
|
label: '姓名',
|
||||||
|
required: true,
|
||||||
|
validateOnChange: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'input-text',
|
||||||
|
name: 'email',
|
||||||
|
label: '邮箱',
|
||||||
|
required: true,
|
||||||
|
validateOnChange: true,
|
||||||
|
validations: {
|
||||||
|
isEmail: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
onEvent: {
|
||||||
|
pureSubmit: {
|
||||||
|
actions: [
|
||||||
|
{
|
||||||
|
actionType: 'toast',
|
||||||
|
args: {
|
||||||
|
msg: '提交成功:${event.data|json}'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
@ -1014,7 +1014,8 @@ export default class Form extends React.Component<FormProps, object> {
|
|||||||
clearPersistDataAfterSubmit,
|
clearPersistDataAfterSubmit,
|
||||||
trimValues,
|
trimValues,
|
||||||
dispatchEvent,
|
dispatchEvent,
|
||||||
translate: __
|
translate: __,
|
||||||
|
$schema
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
// 做动作之前,先把数据同步一下。
|
// 做动作之前,先把数据同步一下。
|
||||||
@ -1822,7 +1823,7 @@ export class FormRenderer extends Form {
|
|||||||
return this.handleAction(undefined, action, data, throwErrors);
|
return this.handleAction(undefined, action, data, throwErrors);
|
||||||
}
|
}
|
||||||
|
|
||||||
handleAction(
|
async handleAction(
|
||||||
e: React.UIEvent<any> | undefined,
|
e: React.UIEvent<any> | undefined,
|
||||||
action: ActionObject,
|
action: ActionObject,
|
||||||
ctx: object,
|
ctx: object,
|
||||||
@ -1833,6 +1834,17 @@ export class FormRenderer extends Form {
|
|||||||
// if (this.props.disabled) {
|
// if (this.props.disabled) {
|
||||||
// return;
|
// return;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
// 配了pureSubmit事件的表示将提交逻辑全部托管给事件
|
||||||
|
const {dispatchEvent, $schema} = this.props;
|
||||||
|
const pureSubmitEvent = $schema?.onEvent?.pureSubmit;
|
||||||
|
const dispatcher = await dispatchEvent(
|
||||||
|
'pureSubmit',
|
||||||
|
this.props.data
|
||||||
|
);
|
||||||
|
if (dispatcher?.prevented || pureSubmitEvent) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (action.target && action.actionType !== 'reload') {
|
if (action.target && action.actionType !== 'reload') {
|
||||||
const scoped = this.context as IScopedContext;
|
const scoped = this.context as IScopedContext;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user