How to synchronize/change value of rich text field?

default discord avatar
DU DA10 months ago
4

I've build an importer to import all the content from one language to another. It's working perfectly fine. The only problem is, that a single rich text field (not nested in an array or block) is not changing its value visibly before submitting/saving the changes. I've rebuild a collection and a synchronization component that is showing the issue. In my example I only want to synchronize a text and a richtext field with 2 field with the same type. I used two different approaches, once with the setValue function of useField and once with the dispatch function of useAllFields, here my Gist:

https://gist.github.com/MarvinVrdoljak/86ba68a6e32efe672f834fba7b4dd41d

So my question: is there any solution to avoid using the submit function, to get the same result? Thanks a lot.



(Payload Version 1.14.0)

  • discord user avatar
    jarrod_not_jared
    10 months ago

    Looks like the key of the editor is determined by

    initialValue

    (this is so it does not rerender when form state changes)



    Could you try setting the initialValue in your dispatch?



    Here is the relevant code:

    https://github.com/payloadcms/payload/blob/master/src/admin/components/forms/field-types/RichText/RichText.tsx#L318-L323
  • default discord avatar
    DU DA10 months ago

    Cheers a lot for your reply. Works perfectly fine on the first synchronization, but if you change the content in the rich text once more (before saving) and try to synchronize the fields again, it's not doing anything.

  • discord user avatar
    jarrod_not_jared
    10 months ago

    I am not sure if I will have time to look into it more today. You could open an issue on github and we can check it out Monday, although I am not sure if there will be an easy solution since it has to do with setting slates internal state. But I would be glad to take a look!

  • default discord avatar
    DU DA10 months ago

    Thanks a lot, will open a ticket then 🙂



    @jarrod_not_jared Was looking into it again and I did a misktake yesterday. Seems to work like this. Thanks a lot for your help.

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

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