antd中自定義驗證方法
阿新 • • 發佈:2018-12-13
<Col xxl={6} xl={12} lg={12}>
<Row>
<Item
{...ItemOneFourth}
label='配載量'
>
{
getFieldDecorator("stowage" + index + j_index, {
initialValue: '',
rules: [
{
validator: this.validateStowage,
}
]
})(
<Input suffix={
<span>{this.state.goodsUnit}</span>}/>
)
}
</Item>
</Row>
</Col>
// 自定義表單驗證 validateStowage =(rule, value, callback)=>{ if(value == ''|| value == null || /^[0-9]*$/.test(value) == false){ callback('請填寫正確內容'); }else{ callback(); } };
//提交
this.props.form.validateFieldsAndScroll( (err) => { if (!err) { Axios.post('url', data).then((res) => {}).catch((err) => {}); } }, );