mirror of
https://gitee.com/baidu/amis.git
synced 2024-12-05 05:18:34 +08:00
Merge pull request #6940 from 2betop/fix-form-submit-event
fix: 修复 form submit 事件触发时机问题 Close: #6901
This commit is contained in:
commit
0ef1446ce5
@ -1068,6 +1068,7 @@ export default class Form extends React.Component<FormProps, object> {
|
|||||||
if (data === this.props.data) {
|
if (data === this.props.data) {
|
||||||
data = store.data;
|
data = store.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Array.isArray(action.required) && action.required.length) {
|
if (Array.isArray(action.required) && action.required.length) {
|
||||||
/** 如果是按钮指定了required,则校验前先清空一下遗留的校验报错 */
|
/** 如果是按钮指定了required,则校验前先清空一下遗留的校验报错 */
|
||||||
store.clearErrors();
|
store.clearErrors();
|
||||||
@ -1101,6 +1102,14 @@ export default class Form extends React.Component<FormProps, object> {
|
|||||||
action.actionType === 'reset-and-submit' ||
|
action.actionType === 'reset-and-submit' ||
|
||||||
action.actionType === 'clear-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);
|
store.setCurrentAction(action);
|
||||||
|
|
||||||
if (action.actionType === 'reset-and-submit') {
|
if (action.actionType === 'reset-and-submit') {
|
||||||
@ -1891,13 +1900,6 @@ export class FormRenderer extends Form {
|
|||||||
// return;
|
// 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') {
|
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