Custom Component Changes Not Enabling Save Draft or Publish Changes

default discord avatar
58bits
3 months ago
2

Posting this here for posterity, and in case anyone else comes across this. In a custom field and field component, changes from

setValue

via

useField

were not 'enabling' the Save Draft or Publish Changes' buttons. Manually calling

setModified(true)

via

useForm

before calling

setValue

solved the issue. This was only occurring when the custom field was used as a field in a block.

  • discord user avatar
    alessiogr
    Payload Team
    2 months ago

    This is weird that that's required. Does that happen to every custom field or only with the lexical one?

  • default discord avatar
    58bits
    2 months ago

    Yeah - it was a puzzle for sure. And it only happens in our custom Lexical field FieldComponent and only (I believe) when it's part of a block field. I ran out of time trying to debug it - but I did test as much as I could including setting up a test repo, and at one point using the identical field definition, but with a swapped out field component (using a simpler component) and it worked. Heh. In the end

    setModified(true)

    just before

    setValue({...})

    worked fine and apparently without any other side effects and so I've left this as a future 'TODO: Revisit'.

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.