名称不能超过20个字

dev_forum
hjm 6 years ago
parent 328fd86b55
commit 41edd7f5e6

@ -22,6 +22,15 @@ class AddDirModal extends Component{
let coursesId = this.props.match.params.coursesId; let coursesId = this.props.match.params.coursesId;
const url = `/courses/${coursesId}/boards.json` const url = `/courses/${coursesId}/boards.json`
let { inputValue } = this.state; let { inputValue } = this.state;
if (!inputValue) {
this.setState({ errorMsg: '名称不能为空'})
return;
}
if (inputValue.length > 20) {
this.setState({ errorMsg: '名称不能超过20个字'})
return;
}
this.setState({ errorMsg: ''})
axios.post(url,{ axios.post(url,{
name: inputValue name: inputValue
@ -36,10 +45,10 @@ class AddDirModal extends Component{
}) })
} }
onCancel = () => { onCancel = () => {
this.setState({ visible: false, inputValue: '' }) this.setState({ visible: false, inputValue: '', errorMsg: '' })
} }
render(){ render(){
let { inputValue, visible } = this.state; let { inputValue, visible, errorMsg } = this.state;
const { title } = this.props; const { title } = this.props;
return( return(
<Modal <Modal
@ -62,6 +71,8 @@ class AddDirModal extends Component{
/> />
</div> </div>
{errorMsg && <span style={{color: 'red'}}>{errorMsg}</span>}
{/* {this.state.NavmodalValuetype===true?<span className={"color-red"}> {/* {this.state.NavmodalValuetype===true?<span className={"color-red"}>
{this.state.NavmodalValues} {this.state.NavmodalValues}
</span>:""} */} </span>:""} */}

Loading…
Cancel
Save