From cc8ae7d1181894d328b85e3abce42f9b7e474a66 Mon Sep 17 00:00:00 2001 From: zhangwenshuai Date: Thu, 23 Jul 2020 18:08:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=A1=A8=E5=8D=95=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../base/extra/dataEntry/textSelect/index.tsx | 10 +++---- components/apolloTable/editFormV3/index.tsx | 30 ++++++++++++++++++- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/components/apolloTable/component/base/extra/dataEntry/textSelect/index.tsx b/components/apolloTable/component/base/extra/dataEntry/textSelect/index.tsx index 946f99b..d7bbb79 100644 --- a/components/apolloTable/component/base/extra/dataEntry/textSelect/index.tsx +++ b/components/apolloTable/component/base/extra/dataEntry/textSelect/index.tsx @@ -137,11 +137,7 @@ class TextSelect extends React.Component { onChange = (obj) => { const { onChange } = this.props; if (typeof onChange === 'function') { - if (!obj || (!obj.label && !obj.value)) { - onChange(undefined); - } else { - onChange(obj); - } + onChange(obj); } }; @@ -158,7 +154,11 @@ class TextSelect extends React.Component { }; onVisibleChange = (tempVisible) => { + const { onDropdownVisibleChange } = this.props; this.setState({ tempVisible }); + if (onDropdownVisibleChange) { + onDropdownVisibleChange(tempVisible); + } }; renderList = () => { diff --git a/components/apolloTable/editFormV3/index.tsx b/components/apolloTable/editFormV3/index.tsx index 1192ea5..f9c795a 100644 --- a/components/apolloTable/editFormV3/index.tsx +++ b/components/apolloTable/editFormV3/index.tsx @@ -89,6 +89,30 @@ class FormWrap extends Component { ); }; + validateRequired = (item, rule, value, callback) => { + if (!item.requiredFlag) { + return callback(); + } + if (!value) { + return callback('必填项不能为空'); + } + if (Array.isArray(value)) { + if (value.length === 0) { + return callback('必填项不能为空'); + } + const [first] = value; + if (!first.text && first.text !== 0 && !first.value && first.value !== 0) { + return callback('必填项不能为空'); + } + } + if (typeof value === 'object') { + if (!value.text && value.text !== 0 && !value.value && value.value !== 0) { + return callback('必填项不能为空'); + } + } + return callback(); + }; + renderEditForm = (item) => { const { getFieldDecorator } = this.props.form; const { rowData, rowId, getInstanceDetail, onBlurFn } = this.props; @@ -141,7 +165,11 @@ class FormWrap extends Component { {getFieldDecorator(columnName, { validateFirst, validateTrigger, - rules: [{ required: !!item.requiredFlag, message: '必填项不能为空' }, ...rules], + rules: [ + { required: !!item.requiredFlag, message: '必填项不能为空' }, + { validator: this.validateRequired.bind(this, item) }, + ...rules, + ], initialValue: getFormat(detailConfig, item, value), })(