field-form
field-form copied to clipboard
antd的form的shouldUpdate执行了validator没有执行
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>
为什么不直接用denpends不是更简单吗?