I'm trying to create 2 Form Items with antd (netWeight and grossWeight) and I want to maske sure the Net Weight is always smaller than the grossWeight.
I've found the following example https://ant.design/components/form/#components-form-demo-register
with the following lines of code
<Form.Item
name="password"
label="Password"
rules={[
{
required: true,
message: 'Please input your password!',
},
]}
hasFeedback
>
<Input.Password />
</Form.Item>
<Form.Item
name="confirm"
label="Confirm Password"
dependencies={['password']}
hasFeedback
rules={[
{
required: true,
message: 'Please confirm your password!',
},
({ getFieldValue }) => ({
validator(_, value) {
console.log(value); // I added this line to see when it runs
if (!value || getFieldValue('password') === value) {
return Promise.resolve();
}
return Promise.reject('The two passwords that you entered do not match!');
},
}),
]}
>
<Input.Password />
</Form.Item>
I've rebuild that for my case, however I don't understand why validator triggers if either "password" or "confirm" change (since it's only a rule for "confirm")
question from:
https://stackoverflow.com/questions/65902822/ant-design-when-does-the-form-rule-validator-trigger 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…