Skip to content
Source
Sign inSign up
TanStack/form

onChange and onBlur validation errors should prevent submission of form #490

Send to my agent
Closedcrutchcorn(GitHub profile, opens in a new tab) opened this issue 9 comments

Currently, when using a field with:

<Field onChange={z.string().min(1)}>

When the user submits the form, it does not show a form error on submit. This causes headaches currently as it makes things harder to workflow properly.

  1. crutchcorn(GitHub profile, opens in a new tab) added labelstype: bug

  2. crutchcorn(GitHub profile, opens in a new tab) added labelsgood first issue

  3. Hey @crutchcorn Can you assign this to me please

  4. crutchcorn(GitHub profile, opens in a new tab) assignedvikaskumar89

  5. Can you aasign this issue to me?

  6. hey @I-MirzaBaig I am working on this. Could you pick any other open issue.

  7. Hey @crutchcorn The root cause of this error is because we have defined undefined for the submit cause that leads to validateSync returning early and not executing any onBlur/onChange validation.

    error rootcause: https://github.com/TanStack/form/blob/fd1945318849769056c674bf9e80bdf6add12b6e/packages/form-core/src/FieldApi.ts#L337

    One solution that comes to my mind is in case of submit cause, we can execute either onChange or onBlur validation(whichever is defined in the field) but this would lead to incorrect errorMap detail in the state as the errorMapKey would be submit and the error would correspond to onChange/onBlur.

    Do you have any alternate suggestion to fix this ?

  8. Due to this errorMap array, we are facing this issue in https://github.com/TanStack/form/issues/486, as the errorMap is not clear after a valid value is entered.

  9. Is there currently a workaround to this?

  10. @danteissaias yeah fix should be out in a couple of days.

  11. This fix is released in 0.10.0!

Sign in to join this conversation.