T
TanStack•2mo ago
exotic-emerald

many setFieldValue breaks form validators

What happens is that when I click on a record in a table, I need to transfer this data to the inputs validated by Zod. To achieve this, I created a function that passes the clicked data with several form.setFieldValues. The data appears correctly, but Zod detects the fields as errors. I tried form.validate() but it didn't change anything. const form = useForm({ validators: { onChangeAsyncDebounceMs: 800, onChangeAsync: formSchema, }, ... const handleClickDataGrid = (params) => { form.setFieldValue("esEdicion", true) form.setFieldValue("tipoProdC", params.row.tipoprodc) const listaOrigen = params.row.tipoprodc === "I" ? listaInsumos : listaQuimicos const producto = listaOrigen.find((item) => item.nroprod === params.row.nroprodc) form.setFieldValue("nroProdC", producto) form.setFieldValue("cantidad", params.row.cantidad) const persona = listaPersonas.find((item) => item.codper === params.row.codperaut) form.setFieldValue("codPerAut", persona) form.setFieldValue("tipoAut", params.row.tipoaut) }
4 Replies
other-emerald
other-emerald•2mo ago
I guess it depends on if you're only validating on the form-level or also on the field-level. You can try one of these methods (maybe you need both):
// validate on form level
form.validate("change");

// validate on field level
form.validateAllFields("change")
// validate on form level
form.validate("change");

// validate on field level
form.validateAllFields("change")
exotic-emerald
exotic-emeraldOP•2mo ago
What does the "change" mean within the validate?
other-emerald
other-emerald•2mo ago
validate: (cause: ValidationCause)
validate: (cause: ValidationCause)
export type ValidationCause = 'change' | 'blur' | 'submit' | 'mount' | 'server'
export type ValidationCause = 'change' | 'blur' | 'submit' | 'mount' | 'server'
exotic-emerald
exotic-emeraldOP•2mo ago
thank you! that worked 😄

Did you find this page helpful?