Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions packages/components/form/FormItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { useLocaleReceiver } from '../locale/LocalReceiver';
import { NATIVE_INPUT_COMP, TD_CTRL_PROP_MAP, ValidateStatus } from './const';
import { formItemDefaultProps } from './defaultProps';
import { useFormContext, useFormListContext } from './FormContext';
import { parseMessage, validate as validateModal } from './formModel';
import { parseMessage, validate as validateModel } from './formModel';
import { HOOK_MARK } from './hooks/useForm';
import useFormItemInitialData from './hooks/useFormItemInitialData';
import useFormItemStyle from './hooks/useFormItemStyle';
Expand Down Expand Up @@ -238,10 +238,13 @@ const FormItem = forwardRef<FormItemInstance, FormItemProps>((originalProps, ref
return result;
}
result.allowSetValue = true;
result.resultList = await validateModal(formValue, result.rules);
result.resultList = await validateModel(formValue, result.rules);
result.errorList = result.resultList
.filter((item) => item.result !== true)
.filter((item) => item?.result !== true)
.map((item) => {
if (!item || typeof item !== 'object') {
return item;
}
Object.keys(item).forEach((key) => {
if (!item.message && errorMessages[key]) {
// eslint-disable-next-line
Expand All @@ -255,9 +258,8 @@ const FormItem = forwardRef<FormItemInstance, FormItemProps>((originalProps, ref
});
// 仅有自定义校验方法才会存在 successList
result.successList = result.resultList.filter(
(item) => item.result === true && item.message && item.type === 'success',
(item) => item && item.result === true && item.message && item.type === 'success',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为什么一个补充的是 optional? 一个补充又是的 item &&

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

因为这里 item 太多了... 直接 && 似乎比较快

);

return result;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/components/form/hooks/useInstance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ function formatValidateResult(validateResultList) {
Object.keys(result).forEach((key) => {
if (result[key] === true) {
delete result[key];
} else {
result[key] = result[key].filter((fr: AllValidateResult) => fr.result === false);
} else if (Array.isArray(result[key])) {
result[key] = result[key].filter((fr: AllValidateResult) => fr?.result === false);
}

// 整理嵌套数据
Expand Down
Loading