mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-22 22:48:29 +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
78 lines
2.3 KiB
TypeScript
78 lines
2.3 KiB
TypeScript
import React from 'react';
|
|
import { Button, DatePicker, Form, TimePicker } from 'antd';
|
|
|
|
const { RangePicker } = DatePicker;
|
|
|
|
const formItemLayout = {
|
|
labelCol: {
|
|
xs: { span: 24 },
|
|
sm: { span: 8 },
|
|
},
|
|
wrapperCol: {
|
|
xs: { span: 24 },
|
|
sm: { span: 16 },
|
|
},
|
|
};
|
|
|
|
const config = {
|
|
rules: [{ type: 'object' as const, required: true, message: 'Please select time!' }],
|
|
};
|
|
|
|
const rangeConfig = {
|
|
rules: [{ type: 'array' as const, required: true, message: 'Please select time!' }],
|
|
};
|
|
|
|
const onFinish = (fieldsValue: any) => {
|
|
// Should format date value before submit.
|
|
const rangeValue = fieldsValue['range-picker'];
|
|
const rangeTimeValue = fieldsValue['range-time-picker'];
|
|
const values = {
|
|
...fieldsValue,
|
|
'date-picker': fieldsValue['date-picker'].format('YYYY-MM-DD'),
|
|
'date-time-picker': fieldsValue['date-time-picker'].format('YYYY-MM-DD HH:mm:ss'),
|
|
'month-picker': fieldsValue['month-picker'].format('YYYY-MM'),
|
|
'range-picker': [rangeValue[0].format('YYYY-MM-DD'), rangeValue[1].format('YYYY-MM-DD')],
|
|
'range-time-picker': [
|
|
rangeTimeValue[0].format('YYYY-MM-DD HH:mm:ss'),
|
|
rangeTimeValue[1].format('YYYY-MM-DD HH:mm:ss'),
|
|
],
|
|
'time-picker': fieldsValue['time-picker'].format('HH:mm:ss'),
|
|
};
|
|
console.log('Received values of form: ', values);
|
|
};
|
|
|
|
const App: React.FC = () => (
|
|
<Form
|
|
name="time_related_controls"
|
|
{...formItemLayout}
|
|
onFinish={onFinish}
|
|
style={{ maxWidth: 600 }}
|
|
>
|
|
<Form.Item name="date-picker" label="DatePicker" {...config}>
|
|
<DatePicker />
|
|
</Form.Item>
|
|
<Form.Item name="date-time-picker" label="DatePicker[showTime]" {...config}>
|
|
<DatePicker showTime format="YYYY-MM-DD HH:mm:ss" />
|
|
</Form.Item>
|
|
<Form.Item name="month-picker" label="MonthPicker" {...config}>
|
|
<DatePicker picker="month" />
|
|
</Form.Item>
|
|
<Form.Item name="range-picker" label="RangePicker" {...rangeConfig}>
|
|
<RangePicker />
|
|
</Form.Item>
|
|
<Form.Item name="range-time-picker" label="RangePicker[showTime]" {...rangeConfig}>
|
|
<RangePicker showTime format="YYYY-MM-DD HH:mm:ss" />
|
|
</Form.Item>
|
|
<Form.Item name="time-picker" label="TimePicker" {...config}>
|
|
<TimePicker />
|
|
</Form.Item>
|
|
<Form.Item label={null}>
|
|
<Button type="primary" htmlType="submit">
|
|
Submit
|
|
</Button>
|
|
</Form.Item>
|
|
</Form>
|
|
);
|
|
|
|
export default App;
|