Support

Account

Home Forums Gutenberg Force fields updated with JS to update?

Unread

Force fields updated with JS to update?

  • Hi,

    I’m currently working on an icon selector, that basically open a modal containing several icon you can pick. In order to do so, I created a custom field type for ACF with an input with the type “hidden”, following these steps.
    Basically I use a script that opens a modal if you click on the icon preview of the field, and you can pick an icon from here. When you click on one, it closes the modal, and update both the icon preview’s src and the hidden input field’s value.

    I also created a custom block with ACF too, and assign a fields group to make it contain my custom icon-selector field type, including a title (simple ACF text field).

    Everything works fine as it is, but only the first time you select an icon.

    After that, in despite of the input value being updated, WordPress doesn’t seem to trigger an event saying “hey, the field’s value has changed, I need to update it on post save”.
    What exactly happens behind the scenes sounds quite mysterious for me but is my guess because, if you change the other field of the block in the meantime (the title), then it considers the block fields have changed, and also save correctly the icon modification.

    Hence my question: is there a way to force WordPress to consider that the block updated when the field’s value changed with JS?

    Thank you in advance.

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.