//排序
sortModalSubmit = async () => {
const { examInfo, subjectInfo, type } = this.state;
console.log('ref', this.sortForm);
const values = await this.sortForm.validateFields(); // TypeError this.sortForm.validateFields is not a function 这里报错
const params = { ...values, id: type === 'examType' ? examInfo.id : subjectInfo.id, type };
let res = request('/api/online-school/admin/exam/sort', {
method: 'POST',
body: JSON.stringify(params),
})
}
<Modal maskClosable={false} title="排序" visible={true} onOk={this.sortModalSubmit}
onCancel={() => {
this.setState({ sortVisible: false })
}} bodyStyle={{ display: 'flex' }}>
<Form
ref={form => {this.sortForm = form}}
>
<Form.Item
{...formProps}
label="排序序号"
required
>
{getFieldDecorator('sortNum', {
})(<InputNumber min={1} />)}
</Form.Item>
</Form>
</Modal>
我用的react版本是"react": "^15.5.4","antd": "^2.12.3",这个react文档获取类组件ref就是这样写的.不过antd文档没有给这方面的说明.
请问我要怎么获取form表单的实例,来手动触发validateFields()拿到表单中的值
因为页面有很多model弹窗所以存在多个表单组件
官方2.x文档