mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-05 17:59:57 +08:00
67ee019478
* feat: reset and force update * feat: update package * feat: reset * feat: update for viewer * feat: update for viewer * feat: update for viewer * feat: update for viewer * feat: update for viewer * update doc * feat: add waring * feat: update doc * feat: add test case
97 lines
2.1 KiB
TypeScript
97 lines
2.1 KiB
TypeScript
import React from 'react';
|
|
import { Button, Form, Mentions } from 'antd';
|
|
|
|
const { getMentions } = Mentions;
|
|
|
|
const App: React.FC = () => {
|
|
const [form] = Form.useForm();
|
|
|
|
const onReset = () => {
|
|
form.resetFields();
|
|
};
|
|
|
|
const onFinish = async () => {
|
|
try {
|
|
const values = await form.validateFields();
|
|
console.log('Submit:', values);
|
|
} catch (errInfo) {
|
|
console.log('Error:', errInfo);
|
|
}
|
|
};
|
|
|
|
const checkMention = async (_: any, value: string) => {
|
|
const mentions = getMentions(value);
|
|
|
|
if (mentions.length < 2) {
|
|
throw new Error('More than one must be selected!');
|
|
}
|
|
};
|
|
|
|
return (
|
|
<Form form={form} layout="horizontal" onFinish={onFinish}>
|
|
<Form.Item
|
|
name="coders"
|
|
label="Top coders"
|
|
labelCol={{ span: 6 }}
|
|
wrapperCol={{ span: 16 }}
|
|
rules={[{ validator: checkMention }]}
|
|
>
|
|
<Mentions
|
|
rows={1}
|
|
options={[
|
|
{
|
|
value: 'afc163',
|
|
label: 'afc163',
|
|
},
|
|
{
|
|
value: 'zombieJ',
|
|
label: 'zombieJ',
|
|
},
|
|
{
|
|
value: 'yesmeck',
|
|
label: 'yesmeck',
|
|
},
|
|
]}
|
|
/>
|
|
</Form.Item>
|
|
<Form.Item
|
|
name="bio"
|
|
label="Bio"
|
|
labelCol={{ span: 6 }}
|
|
wrapperCol={{ span: 16 }}
|
|
rules={[{ required: true }]}
|
|
>
|
|
<Mentions
|
|
rows={3}
|
|
placeholder="You can use @ to ref user here"
|
|
options={[
|
|
{
|
|
value: 'afc163',
|
|
label: 'afc163',
|
|
},
|
|
{
|
|
value: 'zombieJ',
|
|
label: 'zombieJ',
|
|
},
|
|
{
|
|
value: 'yesmeck',
|
|
label: 'yesmeck',
|
|
},
|
|
]}
|
|
/>
|
|
</Form.Item>
|
|
<Form.Item wrapperCol={{ span: 14, offset: 6 }}>
|
|
<Button htmlType="submit" type="primary">
|
|
Submit
|
|
</Button>
|
|
|
|
<Button htmlType="button" onClick={onReset}>
|
|
Reset
|
|
</Button>
|
|
</Form.Item>
|
|
</Form>
|
|
);
|
|
};
|
|
|
|
export default App;
|