2019-07-03 20:14:39 +08:00
---
order: 5
title:
zh-CN: 嵌套结构与校验信息
en-US: Nest
---
## zh-CN
`name` 属性支持嵌套数据结构。通过 `validateMessages` 或 `message` 自定义校验信息模板,模板内容可参考[此处](https://github.com/react-component/field-form/blob/master/src/utils/messages.ts)。
## en-US
`name` prop support nest data structure. Customize validate message template with `validateMessages` or `message` . Ref [here ](https://github.com/react-component/field-form/blob/master/src/utils/messages.ts ) about message template.
```tsx
import { Form, Input, InputNumber, Button } from 'antd';
const layout = {
labelCol: { span: 8 },
wrapperCol: { span: 16 },
};
const validateMessages = {
2020-03-03 21:57:06 +08:00
required: '${label} is required!',
2019-07-03 20:14:39 +08:00
types: {
2020-11-07 02:49:30 +08:00
email: '${label} is not a valid email!',
number: '${label} is not a valid number!',
2019-07-03 20:14:39 +08:00
},
number: {
2020-03-03 21:57:06 +08:00
range: '${label} must be between ${min} and ${max}',
2019-07-03 20:14:39 +08:00
},
};
const Demo = () => {
2020-12-17 15:09:18 +08:00
const onFinish = (values: any) => {
2019-07-03 20:14:39 +08:00
console.log(values);
};
return (
< Form { . . . layout } name = "nest-messages" onFinish = {onFinish} validateMessages = {validateMessages} >
< Form.Item name = {['user', ' name ' ] } label = "Name" rules = {[{ required: true } ] } >
< Input / >
< / Form.Item >
< Form.Item name = {['user', ' email ' ] } label = "Email" rules = {[{ type: ' email ' } ] } >
< Input / >
< / Form.Item >
< Form.Item name = {['user', ' age ' ] } label = "Age" rules = {[{ type: ' number ' , min: 0 , max: 99 } ] } >
< InputNumber / >
< / Form.Item >
< Form.Item name = {['user', ' website ' ] } label = "Website" >
< Input / >
< / Form.Item >
< Form.Item name = {['user', ' introduction ' ] } label = "Introduction" >
< Input.TextArea / >
< / Form.Item >
< Form.Item wrapperCol = {{ . . . layout . wrapperCol , offset: 8 } } >
< Button type = "primary" htmlType = "submit" >
Submit
< / Button >
< / Form.Item >
< / Form >
);
};
ReactDOM.render(< Demo / > , mountNode);
```