fix: 修复 form submit 事件触发时机问题 Close: #6901

This commit is contained in:
liaoxuezhi 2023-05-20 09:48:16 +08:00
parent 0f63e1bbbc
commit 152dd0716c

View File

@ -1052,6 +1052,7 @@ export default class Form extends React.Component<FormProps, object> {
if (data === this.props.data) {
data = store.data;
}
if (Array.isArray(action.required) && action.required.length) {
/** 如果是按钮指定了required则校验前先清空一下遗留的校验报错 */
store.clearErrors();
@ -1085,6 +1086,14 @@ export default class Form extends React.Component<FormProps, object> {
action.actionType === 'reset-and-submit' ||
action.actionType === 'clear-and-submit'
) {
// 配了submit事件的表示将提交逻辑全部托管给事件
const {dispatchEvent, onEvent} = this.props;
const submitEvent = onEvent?.submit?.actions?.length;
const dispatcher = await dispatchEvent('submit', this.props.data);
if (dispatcher?.prevented || submitEvent) {
return;
}
store.setCurrentAction(action);
if (action.actionType === 'reset-and-submit') {
@ -1873,13 +1882,6 @@ export class FormRenderer extends Form {
// return;
// }
// 配了submit事件的表示将提交逻辑全部托管给事件
const {dispatchEvent, onEvent} = this.props;
const submitEvent = onEvent?.submit?.actions?.length;
const dispatcher = await dispatchEvent('submit', this.props.data);
if (dispatcher?.prevented || submitEvent) {
return;
}
if (action.target && action.actionType !== 'reload') {
const scoped = this.context as IScopedContext;