-
I have a field, for example addressAdition" with a value that I get from the database. I use ...setFormDefaults(formId), {addressAdition: "someValue"} to set the default value. If I remove the value in the field the value is undefined and therefore no update is send to the database. How would you update a value to null? Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Hi! This depends a lot on your exact setup (your database, business logic, which validation lib you're using etc). In your action, in the raw FormData object you get from the request, the value of this field should always be at least an empty string unless the input is disabled or removed from the DOM. If that's not the case, then something is happening after that to make it undefined. If I had to guess, it sounds like you might be validating this input with [zod-form-data's text helper] (https://www.remix-validated-form.io/zod-form-data/api-reference#text), because that explicitly transforms empty strings to undefined. If you want something other than undefined, you could use something else (e.g. plain I hope that helps! |
Beta Was this translation helpful? Give feedback.
-
Hi @airjp73 , thanks for the response. Yes this pattern ( |
Beta Was this translation helpful? Give feedback.
-
Yeah, it sounds like your case would work best just using |
Beta Was this translation helpful? Give feedback.
Yeah, it sounds like your case would work best just using
z.string()
.