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•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):
exotic-emeraldOP•2mo ago
What does the "change" mean within the validate?
other-emerald•2mo ago
exotic-emeraldOP•2mo ago
thank you! that worked 😄