Commit cc8ae7d1 authored by zhangwenshuai's avatar zhangwenshuai

修改表单校验

parent 897f03ef
......@@ -137,11 +137,7 @@ class TextSelect extends React.Component<Props, State> {
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<Props, State> {
};
onVisibleChange = (tempVisible) => {
const { onDropdownVisibleChange } = this.props;
this.setState({ tempVisible });
if (onDropdownVisibleChange) {
onDropdownVisibleChange(tempVisible);
}
};
renderList = () => {
......
......@@ -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),
})(
<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