mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-21 13:18:04 +08:00
54fb6bd831
* feat: Form.Item support noLabel * feat: doc * feat: test * feat: test * feat: test * feat: review * feat: review * feat: 仅支持 span * feat: review * feat: review * feat: review * feat: review * feat: review * feat: test * feat: test * feat: test * feat: test * feat: test * feat: test * feat: add test * feat: demo * feat: test * feat: test * feat: test * feat: 代码优化 * feat: add labelCol * feat: 代码优化 * feat: 代码优化 * feat: reset * feat: test * feat: test * feat: review * feat: doc
56 lines
1.3 KiB
TypeScript
56 lines
1.3 KiB
TypeScript
import React from 'react';
|
|
import { Button, Form, Input, InputNumber } from 'antd';
|
|
|
|
const layout = {
|
|
labelCol: { span: 8 },
|
|
wrapperCol: { span: 16 },
|
|
};
|
|
|
|
const validateMessages = {
|
|
required: '${label} is required!',
|
|
types: {
|
|
email: '${label} is not a valid email!',
|
|
number: '${label} is not a valid number!',
|
|
},
|
|
number: {
|
|
range: '${label} must be between ${min} and ${max}',
|
|
},
|
|
};
|
|
|
|
const onFinish = (values: any) => {
|
|
console.log(values);
|
|
};
|
|
|
|
const App: React.FC = () => (
|
|
<Form
|
|
{...layout}
|
|
name="nest-messages"
|
|
onFinish={onFinish}
|
|
style={{ maxWidth: 600 }}
|
|
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 label={null}>
|
|
<Button type="primary" htmlType="submit">
|
|
Submit
|
|
</Button>
|
|
</Form.Item>
|
|
</Form>
|
|
);
|
|
|
|
export default App;
|