diff --git a/mock/cfc/index.js b/mock/cfc/index.js index cda6b5aea..143e2d791 100755 --- a/mock/cfc/index.js +++ b/mock/cfc/index.js @@ -56,7 +56,11 @@ function mockResponse(event, context, callback) { function createHeaders(headers) { let referer = ''; - if (/^(https?\:\/\/[^:\/]+(?:\:\d+)?\/)/i.test(headers['Referer'])) { + if ( + /^(https?\:\/\/[^:\/]+(?:\:\d+)?\/)/i.test( + headers['Referer'] || headers['referer'] + ) + ) { referer = RegExp.$1.replace(/\/$/, ''); } diff --git a/packages/amis-core/src/renderers/wrapControl.tsx b/packages/amis-core/src/renderers/wrapControl.tsx index f0bf2c075..8134055d5 100644 --- a/packages/amis-core/src/renderers/wrapControl.tsx +++ b/packages/amis-core/src/renderers/wrapControl.tsx @@ -423,6 +423,7 @@ export function wrapControl< ? 'formInited' : 'dataChanged' ); + this.checkValidate(); } } } @@ -513,32 +514,44 @@ export function wrapControl< } } + checkValidate() { + if (!this.model) return; // 如果 model 为 undefined 则直接返回 + const validated = this.model.validated; + const {formSubmited, validateOnChange} = this.props; + + if ( + // 如果配置了 minLength 或者 maxLength 就切成及时验证 + // this.model.rules.minLength || + // this.model.rules.maxLength || + validateOnChange === true || + (validateOnChange !== false && (formSubmited || validated)) + ) { + this.validate(); + } else if (validateOnChange === false) { + this.model?.reset(); + } + } + async validate() { + if (!this.model) return; const {formStore: form, data, formItemDispatchEvent} = this.props; let result; - if (this.model) { - if ( - this.model.unique && - form?.parentStore && - form.parentStore.storeType === ComboStore.name - ) { - const combo = form.parentStore as IComboStore; - const group = combo.uniques.get( - this.model.name - ) as IUniqueGroup; - const validPromises = group.items.map(item => - item.validate(data) - ); - result = await Promise.all(validPromises); - } else { - const validPromises = form - ?.getItemsByName(this.model.name) - .map(item => item.validate(data)); - if (validPromises && validPromises.length) { - result = await Promise.all(validPromises); - } - } + + if ( + this.model.unique && + form?.parentStore && + form.parentStore.storeType === ComboStore.name + ) { + const combo = form.parentStore as IComboStore; + const group = combo.uniques.get(this.model.name) as IUniqueGroup; + const validPromises = group.items.map(item => + item.validate(data) + ); + result = await Promise.all(validPromises); + } else { + result = [await this.model.validate(data)]; } + if (result && result.length) { if (result.indexOf(false) > -1) { formItemDispatchEvent('formItemValidateError', data); @@ -655,20 +668,8 @@ export function wrapControl< return; } - const validated = this.model.validated; onChange?.(value, name!, submitOnChange === true); - - if ( - // 如果配置了 minLength 或者 maxLength 就切成及时验证 - // this.model.rules.minLength || - // this.model.rules.maxLength || - validateOnChange === true || - (validateOnChange !== false && (formSubmited || validated)) - ) { - this.validate(); - } else if (validateOnChange === false) { - this.model?.reset(); - } + this.checkValidate(); } handleBlur(e: any) { diff --git a/packages/amis-core/src/store/form.ts b/packages/amis-core/src/store/form.ts index 550c6bebf..509f352be 100644 --- a/packages/amis-core/src/store/form.ts +++ b/packages/amis-core/src/store/form.ts @@ -92,7 +92,7 @@ export const FormStore = ServiceStore.named('FormStore') /** 获取InputGroup的子元素 */ get inputGroupItems() { const formItems: Record = {}; - const children = self.children.concat(); + const children: Array = this.directItems.concat(); while (children.length) { const current = children.shift(); diff --git a/packages/amis/src/renderers/Form/InputGroup.tsx b/packages/amis/src/renderers/Form/InputGroup.tsx index 068d99acd..e6a496697 100644 --- a/packages/amis/src/renderers/Form/InputGroup.tsx +++ b/packages/amis/src/renderers/Form/InputGroup.tsx @@ -120,6 +120,9 @@ export class InputGroup extends React.Component< } const chidren = formStore?.inputGroupItems?.[name]; + if (!Array.isArray(chidren)) { + return; + } const errorCollection = chidren .map((item, index) => { if (item.errors.length <= 0) {