2019-07-03 20:14:39 +08:00
|
|
|
---
|
|
|
|
order: 24
|
|
|
|
title:
|
|
|
|
zh-CN: 校验其他组件
|
|
|
|
en-US: Other Form Controls
|
|
|
|
---
|
|
|
|
|
|
|
|
## zh-CN
|
|
|
|
|
|
|
|
以上演示没有出现的表单控件对应的校验演示。
|
|
|
|
|
|
|
|
## en-US
|
|
|
|
|
|
|
|
Demonstration of validation configuration for form controls which are not shown in the demos above.
|
|
|
|
|
|
|
|
```tsx
|
2022-05-23 14:37:16 +08:00
|
|
|
import { InboxOutlined, UploadOutlined } from '@ant-design/icons';
|
2019-07-03 20:14:39 +08:00
|
|
|
import {
|
2022-05-23 14:37:16 +08:00
|
|
|
Button,
|
|
|
|
Checkbox,
|
|
|
|
Col,
|
2019-07-03 20:14:39 +08:00
|
|
|
Form,
|
|
|
|
InputNumber,
|
|
|
|
Radio,
|
|
|
|
Rate,
|
|
|
|
Row,
|
2022-05-23 14:37:16 +08:00
|
|
|
Select,
|
|
|
|
Slider,
|
|
|
|
Switch,
|
|
|
|
Upload,
|
2019-07-03 20:14:39 +08:00
|
|
|
} from 'antd';
|
2022-05-23 14:37:16 +08:00
|
|
|
import React from 'react';
|
2019-07-03 20:14:39 +08:00
|
|
|
|
|
|
|
const { Option } = Select;
|
|
|
|
|
|
|
|
const formItemLayout = {
|
|
|
|
labelCol: { span: 6 },
|
|
|
|
wrapperCol: { span: 14 },
|
|
|
|
};
|
|
|
|
|
2020-12-17 15:09:18 +08:00
|
|
|
const normFile = (e: any) => {
|
2019-07-03 20:14:39 +08:00
|
|
|
console.log('Upload event:', e);
|
|
|
|
if (Array.isArray(e)) {
|
|
|
|
return e;
|
|
|
|
}
|
2022-05-19 09:46:26 +08:00
|
|
|
return e?.fileList;
|
2019-07-03 20:14:39 +08:00
|
|
|
};
|
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
const App: React.FC = () => {
|
2020-12-17 15:09:18 +08:00
|
|
|
const onFinish = (values: any) => {
|
2019-07-03 20:14:39 +08:00
|
|
|
console.log('Received values of form: ', values);
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Form
|
|
|
|
name="validate_other"
|
|
|
|
{...formItemLayout}
|
|
|
|
onFinish={onFinish}
|
|
|
|
initialValues={{
|
2021-02-23 10:45:11 +08:00
|
|
|
'input-number': 3,
|
|
|
|
'checkbox-group': ['A', 'B'],
|
2019-07-03 20:14:39 +08:00
|
|
|
rate: 3.5,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Form.Item label="Plain Text">
|
|
|
|
<span className="ant-form-text">China</span>
|
|
|
|
</Form.Item>
|
|
|
|
<Form.Item
|
|
|
|
name="select"
|
|
|
|
label="Select"
|
|
|
|
hasFeedback
|
|
|
|
rules={[{ required: true, message: 'Please select your country!' }]}
|
|
|
|
>
|
|
|
|
<Select placeholder="Please select a country">
|
|
|
|
<Option value="china">China</Option>
|
|
|
|
<Option value="usa">U.S.A</Option>
|
|
|
|
</Select>
|
|
|
|
</Form.Item>
|
|
|
|
|
|
|
|
<Form.Item
|
|
|
|
name="select-multiple"
|
|
|
|
label="Select[multiple]"
|
|
|
|
rules={[{ required: true, message: 'Please select your favourite colors!', type: 'array' }]}
|
|
|
|
>
|
|
|
|
<Select mode="multiple" placeholder="Please select favourite colors">
|
|
|
|
<Option value="red">Red</Option>
|
|
|
|
<Option value="green">Green</Option>
|
|
|
|
<Option value="blue">Blue</Option>
|
|
|
|
</Select>
|
|
|
|
</Form.Item>
|
|
|
|
|
|
|
|
<Form.Item label="InputNumber">
|
2019-07-19 14:07:39 +08:00
|
|
|
<Form.Item name="input-number" noStyle>
|
2019-07-03 20:14:39 +08:00
|
|
|
<InputNumber min={1} max={10} />
|
|
|
|
</Form.Item>
|
|
|
|
<span className="ant-form-text"> machines</span>
|
|
|
|
</Form.Item>
|
|
|
|
|
|
|
|
<Form.Item name="switch" label="Switch" valuePropName="checked">
|
|
|
|
<Switch />
|
|
|
|
</Form.Item>
|
|
|
|
|
|
|
|
<Form.Item name="slider" label="Slider">
|
|
|
|
<Slider
|
|
|
|
marks={{
|
|
|
|
0: 'A',
|
|
|
|
20: 'B',
|
|
|
|
40: 'C',
|
|
|
|
60: 'D',
|
|
|
|
80: 'E',
|
|
|
|
100: 'F',
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</Form.Item>
|
|
|
|
|
|
|
|
<Form.Item name="radio-group" label="Radio.Group">
|
|
|
|
<Radio.Group>
|
|
|
|
<Radio value="a">item 1</Radio>
|
|
|
|
<Radio value="b">item 2</Radio>
|
|
|
|
<Radio value="c">item 3</Radio>
|
|
|
|
</Radio.Group>
|
|
|
|
</Form.Item>
|
|
|
|
|
2020-09-22 17:04:48 +08:00
|
|
|
<Form.Item
|
|
|
|
name="radio-button"
|
|
|
|
label="Radio.Button"
|
|
|
|
rules={[{ required: true, message: 'Please pick an item!' }]}
|
|
|
|
>
|
2019-07-03 20:14:39 +08:00
|
|
|
<Radio.Group>
|
|
|
|
<Radio.Button value="a">item 1</Radio.Button>
|
|
|
|
<Radio.Button value="b">item 2</Radio.Button>
|
|
|
|
<Radio.Button value="c">item 3</Radio.Button>
|
|
|
|
</Radio.Group>
|
|
|
|
</Form.Item>
|
|
|
|
|
|
|
|
<Form.Item name="checkbox-group" label="Checkbox.Group">
|
2020-03-03 16:39:50 +08:00
|
|
|
<Checkbox.Group>
|
2019-07-03 20:14:39 +08:00
|
|
|
<Row>
|
|
|
|
<Col span={8}>
|
2020-03-03 16:39:50 +08:00
|
|
|
<Checkbox value="A" style={{ lineHeight: '32px' }}>
|
|
|
|
A
|
|
|
|
</Checkbox>
|
2019-07-03 20:14:39 +08:00
|
|
|
</Col>
|
|
|
|
<Col span={8}>
|
2020-03-03 16:39:50 +08:00
|
|
|
<Checkbox value="B" style={{ lineHeight: '32px' }} disabled>
|
2019-07-03 20:14:39 +08:00
|
|
|
B
|
|
|
|
</Checkbox>
|
|
|
|
</Col>
|
|
|
|
<Col span={8}>
|
2020-03-03 16:39:50 +08:00
|
|
|
<Checkbox value="C" style={{ lineHeight: '32px' }}>
|
|
|
|
C
|
|
|
|
</Checkbox>
|
2019-07-03 20:14:39 +08:00
|
|
|
</Col>
|
|
|
|
<Col span={8}>
|
2020-03-03 16:39:50 +08:00
|
|
|
<Checkbox value="D" style={{ lineHeight: '32px' }}>
|
|
|
|
D
|
|
|
|
</Checkbox>
|
2019-07-03 20:14:39 +08:00
|
|
|
</Col>
|
|
|
|
<Col span={8}>
|
2020-03-03 16:39:50 +08:00
|
|
|
<Checkbox value="E" style={{ lineHeight: '32px' }}>
|
|
|
|
E
|
|
|
|
</Checkbox>
|
|
|
|
</Col>
|
|
|
|
<Col span={8}>
|
|
|
|
<Checkbox value="F" style={{ lineHeight: '32px' }}>
|
|
|
|
F
|
|
|
|
</Checkbox>
|
2019-07-03 20:14:39 +08:00
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
</Checkbox.Group>
|
|
|
|
</Form.Item>
|
|
|
|
|
|
|
|
<Form.Item name="rate" label="Rate">
|
|
|
|
<Rate />
|
|
|
|
</Form.Item>
|
|
|
|
|
|
|
|
<Form.Item
|
|
|
|
name="upload"
|
|
|
|
label="Upload"
|
|
|
|
valuePropName="fileList"
|
|
|
|
getValueFromEvent={normFile}
|
|
|
|
extra="longgggggggggggggggggggggggggggggggggg"
|
|
|
|
>
|
|
|
|
<Upload name="logo" action="/upload.do" listType="picture">
|
2020-08-24 16:33:24 +08:00
|
|
|
<Button icon={<UploadOutlined />}>Click to upload</Button>
|
2019-07-03 20:14:39 +08:00
|
|
|
</Upload>
|
|
|
|
</Form.Item>
|
|
|
|
|
|
|
|
<Form.Item label="Dragger">
|
2019-09-16 11:23:26 +08:00
|
|
|
<Form.Item name="dragger" valuePropName="fileList" getValueFromEvent={normFile} noStyle>
|
|
|
|
<Upload.Dragger name="files" action="/upload.do">
|
|
|
|
<p className="ant-upload-drag-icon">
|
2019-11-28 12:34:33 +08:00
|
|
|
<InboxOutlined />
|
2019-09-16 11:23:26 +08:00
|
|
|
</p>
|
|
|
|
<p className="ant-upload-text">Click or drag file to this area to upload</p>
|
|
|
|
<p className="ant-upload-hint">Support for a single or bulk upload.</p>
|
|
|
|
</Upload.Dragger>
|
|
|
|
</Form.Item>
|
2019-07-03 20:14:39 +08:00
|
|
|
</Form.Item>
|
|
|
|
|
|
|
|
<Form.Item wrapperCol={{ span: 12, offset: 6 }}>
|
|
|
|
<Button type="primary" htmlType="submit">
|
|
|
|
Submit
|
|
|
|
</Button>
|
|
|
|
</Form.Item>
|
|
|
|
</Form>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
export default App;
|
2019-07-03 20:14:39 +08:00
|
|
|
```
|