-
Notifications
You must be signed in to change notification settings - Fork 715
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
fix(form): unexpected validate error before unRegister #1752
base: main
Are you sure you want to change the base?
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 0d04313:
|
Codecov ReportPatch coverage:
❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more. Additional details and impacted files@@ Coverage Diff @@
## main #1752 +/- ##
==========================================
+ Coverage 88.01% 88.05% +0.03%
==========================================
Files 433 433
Lines 25246 25253 +7
Branches 6360 6362 +2
==========================================
+ Hits 22221 22236 +15
+ Misses 3025 3017 -8
☔ View full report in Codecov by Sentry. |
text: 'foo', | ||
}); | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个 Demo 我有点疑问哈,跟 description里描述的场景似乎不太一样。
这个test case的逻辑,我理解的是
- 初始 Field Input 有值 'semi'
- 然后将值删除成空字符串,此时触发了校验
- 然后再使用 formApi.setValue 设成另外一个值
- 希望 error 不存在?
() => {
const formRef = useRef();
const change = () => {
formRef.current.formApi.setValue('text', 'foo');
};
return (
<Form
initValues={{
text: 'semi',
}}
ref={formRef}
>
{({ formState }) => (
<>
{!!formState.values.text && (
<Form.Input
field="text"
rules={[
{ required: true },
]}
/>
)}
<Button onClick={() => change()}>change</Button>
</>
)}
</Form>
)
}
@@ -196,6 +202,9 @@ function withField< | |||
if (validatePromise.current !== rootPromise) { | |||
return; | |||
} | |||
if (unmounted.current) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
但这里的改动,我看着像是为了解决 组件触发校验后(例如 async 的validate),如果最终结果return时,field已经被卸载了,就不再消费 error。
跟【动态删除表单项后,再次增加该表单项目时,存在校验错误】严格意义上也不是一码事?
中文模板 / Chinese Template
What kind of change does this PR introduce? (check at least one)
PR description
Fixes #
Changelog
🇨🇳 Chinese
复现步骤请见单元测试。
🇺🇸 English
Checklist
Other
Additional information