amis 1.9.1-beta.24 → 1.9.1-beta.27

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,7 +4,6 @@ import {Renderer, RendererProps} from '../factory';
4
4
  import {SchemaNode, Schema, Action} from '../types';
5
5
  import {filter} from '../utils/tpl';
6
6
  import Modal from '../components/Modal';
7
- import findLast from 'lodash/findLast';
8
7
  import {
9
8
  guid,
10
9
  isVisible,
@@ -943,13 +943,13 @@ export default class Form extends React.Component<FormProps, object> {
943
943
  );
944
944
  }
945
945
 
946
- handleAction(
946
+ async handleAction(
947
947
  e: React.UIEvent<any> | void,
948
948
  action: Action,
949
949
  data: object,
950
950
  throwErrors: boolean = false,
951
951
  delegate?: IScopedContext
952
- ): any {
952
+ ): Promise<any> {
953
953
  const {
954
954
  store,
955
955
  onSubmit,
@@ -987,38 +987,31 @@ export default class Form extends React.Component<FormProps, object> {
987
987
  if (data === this.props.data) {
988
988
  data = store.data;
989
989
  }
990
+
990
991
  if (Array.isArray(action.required) && action.required.length) {
991
992
  store.clearErrors(); // 如果是按钮指定了required,则校验前先清空一下遗留的校验报错
992
-
993
993
  const fields = action.required.map(item => ({
994
994
  name: item,
995
995
  rules: {isRequired: true}
996
996
  }));
997
+ const validationRes = await store.validateFields(fields);
997
998
 
998
- return store.validateFields(fields).then(async result => {
999
- if (!result) {
1000
- const dispatcher = await dispatchEvent(
1001
- 'validateError',
1002
- this.props.data
1003
- );
1004
- if (!dispatcher?.prevented) {
1005
- env.notify('error', __('Form.validateFailed'));
1006
- }
999
+ if (!validationRes) {
1000
+ const dispatcher = await dispatchEvent(
1001
+ 'validateError',
1002
+ this.props.data
1003
+ );
1007
1004
 
1008
- /** 抛异常是为了在dialog中catch这个错误,避免弹窗直接关闭 */
1009
- return Promise.reject(__('Form.validateFailed'));
1010
- } else {
1011
- dispatchEvent('validateSucc', this.props.data);
1012
- this.handleAction(
1013
- e,
1014
- {...action, required: undefined},
1015
- data,
1016
- throwErrors,
1017
- delegate
1018
- );
1019
- return;
1005
+ if (!dispatcher?.prevented) {
1006
+ env.notify('error', __('Form.validateFailed'));
1020
1007
  }
1021
- });
1008
+
1009
+ /** 抛异常是为了在dialog中catch这个错误,避免弹窗直接关闭 */
1010
+ return Promise.reject(__('Form.validateFailed'));
1011
+ } else {
1012
+ /** 重置validated状态,保证submit时触发表单中的校验项 */
1013
+ store.clearErrors();
1014
+ }
1022
1015
  }
1023
1016
  if (
1024
1017
  action.type === 'submit' ||
@@ -22,7 +22,7 @@ import {
22
22
  resolveVariable,
23
23
  resolveVariableAndFilter
24
24
  } from 'amis-formula';
25
- import {isObservable} from 'mobx';
25
+ import {isObservable, isObservableArray} from 'mobx';
26
26
 
27
27
  export {
28
28
  createObject,
@@ -937,7 +937,7 @@ export function everyTree<T extends TreeItem>(
937
937
  paths: Array<T> = [],
938
938
  indexes: Array<number> = []
939
939
  ): boolean {
940
- if (!Array.isArray(tree)) {
940
+ if (!Array.isArray(tree) && !isObservableArray(tree)) {
941
941
  return false;
942
942
  }
943
943
  return tree.every((item, index) => {