2016-11-02 11:24:52 +08:00
---
order: 9
title:
zh-CN: 自行处理表单数据
en-US: Handle Form Data Manually
---
## zh-CN
使用 `Form.create` 处理后的表单具有自动收集数据并校验的功能,但如果您不需要这个功能,或者默认的行为无法满足业务需求,可以选择不使用 `Form.create` 并自行处理数据。
## en-US
`Form.create` will collect and validate form data automatically. But if you don't need this feature or the default behaviour cannot satisfy you business, you can drop `Form.create` and handle form data manually.
````jsx
import { Form, InputNumber } from 'antd';
const FormItem = Form.Item;
2016-11-10 16:11:22 +08:00
function validatePrimeNumber(number) {
if (number === 11) {
2016-11-02 11:24:52 +08:00
return {
2016-11-10 16:11:22 +08:00
validateStatus: 'success',
errorMsg: null,
2016-11-02 11:24:52 +08:00
};
2016-11-10 16:11:22 +08:00
}
return {
validateStatus: 'error',
errorMsg: 'The prime between 8 and 12 is 11!',
};
}
class RawForm extends React.Component {
state = {
number: {
value: 11,
},
};
handleNumberChange = (value) => {
2016-11-02 11:24:52 +08:00
this.setState({
number: {
2016-11-10 16:11:22 +08:00
...validatePrimeNumber(value),
2016-11-02 11:24:52 +08:00
value,
},
});
2016-11-10 16:11:22 +08:00
}
2016-11-02 11:24:52 +08:00
render() {
const formItemLayout = {
2016-11-10 16:11:22 +08:00
labelCol: { span: 7 },
2016-11-02 11:24:52 +08:00
wrapperCol: { span: 12 },
};
const number = this.state.number;
2016-11-10 16:11:22 +08:00
const tips = 'A prime is a natural number greater than 1 that has no positive divisors other than 1 and itself.';
2016-11-02 11:24:52 +08:00
return (
< Form horizontal >
< FormItem
{...formItemLayout}
2016-11-10 16:11:22 +08:00
label="Prime between 8 & 12"
2016-11-02 11:24:52 +08:00
validateStatus={number.validateStatus}
2016-11-10 16:11:22 +08:00
help={number.errorMsg || tips}
2016-11-02 11:24:52 +08:00
>
< InputNumber
min={8}
max={12}
value={number.value}
onChange={this.handleNumberChange}
/>
< / FormItem >
< / Form >
);
2016-11-10 16:11:22 +08:00
}
}
2016-11-02 11:24:52 +08:00
ReactDOM.render(< RawForm / > , mountNode);
````