1.初始置灰
componentDidMount() {
// To disabled submit button at the beginning.
this.props.form.validateFields();
}
2.置灰不显示报错
判断是否有错和输入框是否有空
hasErrors = (fieldsError) => {
return Object.keys(fieldsError).some(field => fieldsError[field])
||Object.keys(this.props.form.getFieldsValue()).some(field => this.props.form.getFieldsValue()[field]===undefined);
}
3.设置在按钮上
<Form.Item>
<Button
size="large"
type="primary"
htmlType="submit"
style={{ width: "100%", marginTop: 12 }}
loading={submitting}
disabled={hasErrors(getFieldsError())}
>
{"提交修改"}
</Button>
</Form.Item>
OK~