field-form icon indicating copy to clipboard operation
field-form copied to clipboard

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

Open nkli opened this issue 2 years ago • 1 comments

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> <Radio value={'xxx'}>xxx</Radio> </Radio.Group> </Form.Item> ) } </Form.Item>

nkli avatar May 12 '23 11:05 nkli

为什么不直接用denpends不是更简单吗?

1075488066 avatar Jun 02 '23 06:06 1075488066