Commit cc8ae7d1 authored by zhangwenshuai's avatar zhangwenshuai

修改表单校验

parent 897f03ef
...@@ -137,11 +137,7 @@ class TextSelect extends React.Component<Props, State> { ...@@ -137,11 +137,7 @@ class TextSelect extends React.Component<Props, State> {
onChange = (obj) => { onChange = (obj) => {
const { onChange } = this.props; const { onChange } = this.props;
if (typeof onChange === 'function') { if (typeof onChange === 'function') {
if (!obj || (!obj.label && !obj.value)) { onChange(obj);
onChange(undefined);
} else {
onChange(obj);
}
} }
}; };
...@@ -158,7 +154,11 @@ class TextSelect extends React.Component<Props, State> { ...@@ -158,7 +154,11 @@ class TextSelect extends React.Component<Props, State> {
}; };
onVisibleChange = (tempVisible) => { onVisibleChange = (tempVisible) => {
const { onDropdownVisibleChange } = this.props;
this.setState({ tempVisible }); this.setState({ tempVisible });
if (onDropdownVisibleChange) {
onDropdownVisibleChange(tempVisible);
}
}; };
renderList = () => { renderList = () => {
......
...@@ -89,6 +89,30 @@ class FormWrap extends Component { ...@@ -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) => { renderEditForm = (item) => {
const { getFieldDecorator } = this.props.form; const { getFieldDecorator } = this.props.form;
const { rowData, rowId, getInstanceDetail, onBlurFn } = this.props; const { rowData, rowId, getInstanceDetail, onBlurFn } = this.props;
...@@ -141,7 +165,11 @@ class FormWrap extends Component { ...@@ -141,7 +165,11 @@ class FormWrap extends Component {
{getFieldDecorator(columnName, { {getFieldDecorator(columnName, {
validateFirst, validateFirst,
validateTrigger, validateTrigger,
rules: [{ required: !!item.requiredFlag, message: '必填项不能为空' }, ...rules], rules: [
{ required: !!item.requiredFlag, message: '必填项不能为空' },
{ validator: this.validateRequired.bind(this, item) },
...rules,
],
initialValue: getFormat(detailConfig, item, value), initialValue: getFormat(detailConfig, item, value),
})( })(
<EditComp <EditComp
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment