TanStackT
TanStack6mo ago
20 replies
crooked-brown

Does the defaultState property in useForm work?

Hi, I'm testing tanstack-form but something is strange.

On mount, I need that the form state isFieldsValid has to be false by default to prevent user submit unfilled form at start.
It seems the best way to do it is to set isFieldsValid property inside the defaultState in the useForm hooks.

But, no matters if I set in the property like defaultState: { isFieldsValid: false } , by default, isFieldsValid stay always true on mount and I can't rely on it to handle disable state for my submit button.

I found a "workaround" to force the isValid state to false directly in the input mais it's not the best.
With this, your should set manualy the property in every input in your form so... not optimized (I tried to do so for the entire form but it's not working too).

You can reproduce the behaviour and test the workaround in this Codesandbox -> https://codesandbox.io/p/devbox/strange-lederberg-4xjp7l

Am I doing something wrong or any advice on this ?
Was this page helpful?