ant-design/components/form/demo/warning-only.md
二货机器人 7a3bf8287f
feat: Form rule support warningOnly that not block form submit (#30829)
* chore: bump rc-field-form

* docs: Demo driven

* refactor: Use event instead

* chore: collection logic update

* chore: clean up

* chore: show warning

* chore: warning no need required mark

* feat: warning example

* docs: mix error

* chore: tmp list

* chore: magic code

* chore: fix motion

* chore: fix style

* chore: clean up useless code

* chore: RM useless import

* chore: RM useless file

* test: Update snapshot

* chore: Should reset

* fix: Memo logic

* fix: Form basic test case

* fix: lint

* chore: back of ref

* test: Update snapshot

* test: RM ueseless test case

* chore: RM useless code
2021-06-04 14:44:41 +08:00

1.4 KiB

order title
3.2
zh-CN en-US
非阻塞校验 No block rule

zh-CN

rule 添加 warningOnly 后校验不再阻塞表单提交。

en-US

rule with warningOnly will not block form submit.

import React from 'react';
import { Form, Input, message, Button, Space } from 'antd';

const Demo = () => {
  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"
    >
      <div style={{ overflow: 'hidden' }}>
        <Form.Item
          name="url"
          label="URL"
          rules={[
            { required: true },
            { type: 'url', warningOnly: true },
            { type: 'string', min: 6 },
          ]}
        >
          <Input placeholder="input placeholder" />
        </Form.Item>
      </div>
      <Form.Item>
        <Space>
          <Button type="primary" htmlType="submit">
            Submit
          </Button>
          <Button htmlType="button" onClick={onFill}>
            Fill
          </Button>
        </Space>
      </Form.Item>
    </Form>
  );
};

ReactDOM.render(<Demo />, mountNode);