Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@tmagic/form 支持必填项或者自定义校验规则吗? #557

Open
frontend-winter opened this issue Nov 24, 2023 · 4 comments
Open

Comments

@frontend-winter
Copy link

表单里面必填项和校验规则还是比较常见的需求,可以加上吗?

@frontend-winter frontend-winter changed the title @tmagic/form 支持必填项获取自定义rules吗? @tmagic/form 支持必填项或者自定义校验规则吗? Nov 24, 2023
@jia000
Copy link
Collaborator

jia000 commented Nov 27, 2023

支持的,可以看ts 定义

@jia000
Copy link
Collaborator

jia000 commented Nov 27, 2023

必填例子

{
  rules: [
          { required: true, message: '请输入内容', trigger: 'blur' },
        ],
}

自定义校验

{
 rules: [
                      {
                        validator: ({ value, callback }) => {
                          if (/^https:\/\//.test(value)) {
                            return callback();
                          }
                          return callback(new Error('请输入https://开头的地址'));
                        },
                      },
                    ],
                  },
}

@frontend-winter
Copy link
Author

点击保存的时候如何校验表单,通过才能保存?

@jia000
Copy link
Collaborator

jia000 commented Dec 21, 2023

新增了props-submit-error/props-form-error两个事件

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants