From 2bc77bad5d4dc12e05156d6715100c03c0dd089d Mon Sep 17 00:00:00 2001 From: hjm <63528605@qq.com> Date: Fri, 6 Sep 2019 16:48:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=BA=E6=95=B0=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/courses/busyWork/NewWorkForm.js | 45 ++++++++++++++++--- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/public/react/src/modules/courses/busyWork/NewWorkForm.js b/public/react/src/modules/courses/busyWork/NewWorkForm.js index 1ae588db2..33d6e4cda 100644 --- a/public/react/src/modules/courses/busyWork/NewWorkForm.js +++ b/public/react/src/modules/courses/busyWork/NewWorkForm.js @@ -110,6 +110,19 @@ class NewWorkForm extends Component{ {/* min={has_commit ? init_max_num : (min_num == undefined ? 2 : min_num + 1) } */} // 已有提交作品,人数范围只能扩大 const { has_commit, max_num, init_max_num, min_num, init_min_num } = this.state; + if (!min_num) { + this.props.showNotification('最小人数不能为空'); + return; + } else if (min_num < 1) { + this.props.showNotification('最小人数不能小于1'); + return; + } else if (!max_num) { + this.props.showNotification('最大人数不能为空'); + return; + } else if (max_num < min_num) { + this.props.showNotification('最大人数不能小于最小人数'); + return; + } if (has_commit) { if (max_num < init_max_num || min_num > init_min_num) { this.props.showNotification(`已有提交作品,人数范围只能扩大(原设置为:${init_min_num} - ${init_max_num})`) @@ -237,9 +250,9 @@ class NewWorkForm extends Component{ } max_num_change = (val) => { if (val < 2) { - this.setState({ - max_num: 2, - }) + // this.setState({ + // max_num: 2, + // }) return; } const { min_num } = this.state; @@ -248,12 +261,31 @@ class NewWorkForm extends Component{ min_num: val <= min_num ? val - 1 : min_num }) } + personNumValidator = (rule, value, callback) => { + const { min_num, max_num } = this.state; + const form = this.props.form; + if (!min_num) { + callback('最小人数不能为空'); + } else if (min_num < 1) { + callback('最小人数不能小于1'); + } else if (!max_num) { + callback('最大人数不能为空'); + } else if (max_num < min_num) { + callback('最大人数不能小于最小人数'); + } else { + callback(); + } + } min_num_change = (val) => { this.setState({ min_num: val }) } base_on_project_change = () => { this.setState({ base_on_project: !this.state.base_on_project }) } + componentDidMount() { + window.$('.groupSetting .ant-form-item-label > label').addClass('ant-form-item-required') + } + render(){ let {typeId,coursesId,pageType}=this.props.match.params; const { getFieldDecorator } = this.props.form; @@ -411,11 +443,13 @@ class NewWorkForm extends Component{ { isGroup && {getFieldDecorator('personNum', { rules: [{ - required: false + // required: true, + // message: '人数不能为空' + // validator: this.personNumValidator // required: true, message: '请输入最小人数和最大人数' }], })( @@ -447,6 +481,7 @@ class NewWorkForm extends Component{

)} +
}