Hey all, I'm trying to add a hook to a text field that takes in a
location
string and uses it to fetch a geoJson object which is then stored in a hidden field called
geoJson
. This part is working great, but I am having trouble deleting the geoJson object when the field is cleared.
In the hook, I am taking in a few arguments
{ operation, value, originalDoc, data }
and I can manipulate the
data
object, but when I try to set the
data.geoJson
field to
null
or
undefined
or even just delete
data.geoJson
the submission works but the data remains in place. If I instead update the field to say an empty object, that will work. I'm just not seeing how to just remove it completely.
I believe I could use the localAPI to update the field, but I'm thinking that there is probably a way to do so in the data object from the hook.
Hi @reepicheep05 sorry for the delay here!
Currently the appropriate way to clear your
data.geoJson
field
isto update it to an empty object.
The idea of clearing / unsetting a field has come up a few times and we plan to add this functionality to our upcoming roadmap.
Someone else raised this over on GitHub, you can keep in the loop here:
https://github.com/payloadcms/payload/discussions/3102Ok, thanks for the reply!
Star
Discord
online
Get dedicated engineering support directly from the Payload team..