diff --git a/components/apolloTable/editFormV3/index.tsx b/components/apolloTable/editFormV3/index.tsx index f8961b262953e37bb542cac9f6111e3846776e2e..44fe0f3692d1ff1cde8445aa5e42b24c909fe836 100644 --- a/components/apolloTable/editFormV3/index.tsx +++ b/components/apolloTable/editFormV3/index.tsx @@ -159,20 +159,6 @@ class FormWrap extends Component { changeValue(changedValue, optionValue); }; const changeValue = async (changedValue: any, optionValue: any) => { - // 校验必填项 - if (requiredFlag) { - if (!changedValue || changedValue.length === 0) { - message.error('该字段为必填项'); - return; - } - if (changedValue.length === 1) { - const data = changedValue[0]; - if (!data.value && !data.text && data.value !== 0) { - message.error('该字段为必填项'); - return; - } - } - } const extraData = FormHelper.changeTableData({ item, changedKey: columnName, @@ -205,6 +191,21 @@ class FormWrap extends Component { disabled={disabled} rowId={rowId} onEmitChange={(changedValue: any, optionValue: any) => { + // 校验必填项 + if (requiredFlag && !changedValue) { + // message.error('必填项不能为空'); + return; + } + // 校验规则 + if (columnAttrObj.rules) { + for (let i = 0; i < columnAttrObj.rules.length; i++) { + const rule = columnAttrObj.rules[i]; + if (rule.pattern && !rule.pattern.test(changedValue)) { + // message.error(rule.message || '请按正确格式填写'); + return; + } + } + } const value = setFormat(detailConfig, item, changedValue, optionValue); emitChange(value, optionValue); }}