Any advantage to setting defaultValues instead of setFieldValue?
We are loading a bunch of values from an API on mount and setting them through setFieldValue.
I see that we can also set them through the useForm defaultValues and I was hoping that doing this would keep the fields isTouched to false. However both approaches seem to result in the fields being isTouched:true so I'm leaning towards just keeping the setFieldValue.
Are there any advantages to using defaultValues instead of just setFieldValue on load? Why would I do either?
6 Replies
sensitive-blueOP•8mo ago
I see it lets me reset the form to those default values.
rare-sapphire•8mo ago
I'm not sure what you’re doing, but personally I'm loading my form data through tanStack query and using the defaultValues like it shows in the docs.
defaultValues doesn’t result in the isTouched being true... I did a quick test with the setFormValue and it dose result in it being the case.
I would imagine that it's coming from somewhere else.
sensitive-blueOP•8mo ago
Good to know that's possible. I'll see what else could be touching those fields.
rare-sapphire•8mo ago
no worries... its actually something you can see in the source code. With the constructor base store not touching the meta, but in the setFieldValue dose.


sensitive-blueOP•8mo ago
Well I figured it out, but I don't like it. 😄
Firing this causes all fields to become touched:
form.validateAllFields("change");
I would expect a field to only be touched when a user has interacted with it or we set the value some other way. Validating all fields doesn't seem like it should result in a 'touch'?
It looks like using
form.validate("change");
does not touch fields.
rare-sapphire•8mo ago
you are correct in that assumption... Thats definitely an interesting choice, I'm sure that theres a reason for it.
