2021-06-04 14:44:41 +08:00
|
|
|
---
|
|
|
|
order: 3.2
|
2021-11-12 11:46:42 +08:00
|
|
|
version: 4.17.0
|
2021-06-04 14:44:41 +08:00
|
|
|
title:
|
|
|
|
zh-CN: 非阻塞校验
|
|
|
|
en-US: No block rule
|
|
|
|
---
|
|
|
|
|
|
|
|
## zh-CN
|
|
|
|
|
|
|
|
`rule` 添加 `warningOnly` 后校验不再阻塞表单提交。
|
|
|
|
|
|
|
|
## en-US
|
|
|
|
|
|
|
|
`rule` with `warningOnly` will not block form submit.
|
|
|
|
|
|
|
|
```tsx
|
2022-05-23 14:37:16 +08:00
|
|
|
import { Button, Form, Input, message, Space } from 'antd';
|
2021-06-04 14:44:41 +08:00
|
|
|
import React from 'react';
|
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
const App: React.FC = () => {
|
2021-06-04 14:44:41 +08:00
|
|
|
const [form] = Form.useForm();
|
|
|
|
|
|
|
|
const onFinish = () => {
|
|
|
|
message.success('Submit success!');
|
|
|
|
};
|
|
|
|
|
|
|
|
const onFinishFailed = () => {
|
|
|
|
message.error('Submit failed!');
|
|
|
|
};
|
|
|
|
|
|
|
|
const onFill = () => {
|
|
|
|
form.setFieldsValue({
|
|
|
|
url: 'https://taobao.com/',
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Form
|
|
|
|
form={form}
|
|
|
|
layout="vertical"
|
|
|
|
onFinish={onFinish}
|
|
|
|
onFinishFailed={onFinishFailed}
|
|
|
|
autoComplete="off"
|
|
|
|
>
|
2021-11-05 15:50:03 +08:00
|
|
|
<Form.Item
|
|
|
|
name="url"
|
|
|
|
label="URL"
|
|
|
|
rules={[{ required: true }, { type: 'url', warningOnly: true }, { type: 'string', min: 6 }]}
|
|
|
|
>
|
|
|
|
<Input placeholder="input placeholder" />
|
|
|
|
</Form.Item>
|
2021-06-04 14:44:41 +08:00
|
|
|
<Form.Item>
|
|
|
|
<Space>
|
|
|
|
<Button type="primary" htmlType="submit">
|
|
|
|
Submit
|
|
|
|
</Button>
|
|
|
|
<Button htmlType="button" onClick={onFill}>
|
|
|
|
Fill
|
|
|
|
</Button>
|
|
|
|
</Space>
|
|
|
|
</Form.Item>
|
|
|
|
</Form>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
export default App;
|
2021-06-04 14:44:41 +08:00
|
|
|
```
|