Capítulo 13 de 29
onChangeListenTo/onBlurListenTo declare which other fields' changes should re-trigger this field's validator — the mechanism behind classics like "confirm password must match password."
onChangeListenTo, a field's onChange validator only re-runs when that field itself changes — editing "password" alone won't re-validate an already-filled "confirm password" field.onChangeListenTo: ['password'] on the confirm_password field's validators makes editing password re-trigger confirm_password's onChange validator.fieldApi.form.getFieldValue('password').onBlurListenTo is the blur-timing equivalent.<form.Field
name="confirm_password"
validators={{
onChangeListenTo: ['password'],
onChange: ({ value, fieldApi }) => {
if (value !== fieldApi.form.getFieldValue('password')) return 'Passwords do not match'
return undefined
},
}}
>
{(field) => (
<input value={field.state.value} onChange={(e) => field.handleChange(e.target.value)} />
)}
</form.Field>
confirm_password re-validates the moment password changes, not just when confirm_password itself is edited.onChangeListenTo/onBlurListenTo.fieldApi.form.getFieldValue(...) is the read side of this pattern — it pulls a live value from anywhere else in the form, not just listened-to fields.getFieldValue/setFieldValue on FormApi.