react-component / react-component/field-form

antd的form的shouldUpdate执行了validator没有执行

Open
#587 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
1k
Forks
286
Avg merge
4d 16h
Merged PRs (30d)
1

Description

a和b的校验都相互依赖,这里用shouldUpdate去做,结果shouldUpdate执行了,对应的validator没有执行。这种应该怎么处理?
<Form.Item
noStyle
shouldUpdate={(pre: any, current: any) => {
const result = JSON.stringify(pre.a) !== JSON.stringify(current.a)
|| JSON.stringify(pre.b) !== JSON.stringify(current.b);
console.log('shouldUpdate', result);
return result;
}}
>
{
() => (
<Form.Item name="a" label="a方式" required rules={[
({ getFieldValue }) => ({
validator(_, value) {
// 依赖b
console.log('validate);
},
})]}>
<Radio.Group disabled={disabled}>
<Radio value={'ddd'}>ddd
<Radio value={'xxx'}>xxx
</Radio.Group>
</Form.Item>
)
}
</Form.Item>

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the supplied Form.Item example with fields a and b, then inspect the shouldUpdate and validator behavior in the form implementation. Confirm whether changing either dependent field invokes the validator, and finish with the expected behavior covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.