Ant Design Form validateTrigger: Unclear validation order when using array of triggers in v5.x
0 reputation · 20 Mar 2022, 09:48 UTC
0 reputation · 20 Mar 2022, 09:48 UTC
Determine the deterministic order in which Ant Design Form validates fields when validateTrigger is set to an array of triggers.
The library accepts an array but does not document the execution sequence. In complex forms this can lead to inconsistent error messages.
validateTrigger is an array, or can it vary between renders?35275 reputation · 20 Mar 2022, 16:40 UTC
Ant Design Form does not guarantee a deterministic validation order when validateTrigger is an array of trigger strings.
validateTrigger prop is passed to rc-field-form's Field component.The array order only influences which listener is registered first; it does not dictate the sequence in which validation runs when multiple triggers fire for the same field or across fields. Because React event handling and field mounting order can vary between renders, the observed validation order can differ.
validateTrigger={['onChange', 'onBlur']}.onFinish handler that logs form.getFieldsValue() and a validateFields callback that logs the field name and trigger.form.validateFields([fieldName], { force: true }) inside a custom event handler (e.g., onBlur) to run validation on demand.dependencies or validateTrigger as a function that returns an array based on the current state.{ sequence: ['onChange', 'onBlur'] } or a validateOrder prop, but this does not exist in v5.x.If you are using React 18’s concurrent rendering mode, please confirm whether you observe non‑deterministic order; this would affect the recommendation to wrap validation in startTransition or use useSyncExternalStore for deterministic timing.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.