[Possible bug] How to clean a field using the dispatch from useFormFields?

default discord avatar
Cerize
6 months ago
4

Hi there! I am using useFormFields to get the dispatch method for an UPDATE action. Sometimes I need to clean a field, so I dispatchName(undefined). That clears the form correctly, but when I click 'Save Draft' the old value reappears and is saved in Mongo. Any insights on what's going on?



const dispatchName = useFormFields(


([_, dispatch]) =>


(value: string) =>


dispatch({


type: 'UPDATE',


path: NamePath,


value: value


})


)



dispatchName(undefined)



P.S: it seems to work better with dispatching 'null'



@jmikrut Do you know if have anyone seen this before?

  • discord user avatar
    jmikrut
    Payload Team
    6 months ago

    yeah you will need to send

    null

    to clear a field

  • default discord avatar
    Cerize
    6 months ago

    thanks @jmikrut for confirming!

Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.