• Resolved skalibran

    (@skalibran)


    Hi,

    right now, a render script of a flexible content entry is loaded just once when editing a page.

    This results in previews being incorrect once edited. Once the backend is refreshed, the preview is great again.

    There is a hook to run custom javascript code:
    “acfe/fields/flexible_content/preview”
    https://ww.wp.xz.cn/support/topic/dynamic-preview-reinit-js-after-block-update/

    This can help during development and when creating small projects, but creating dynamic page elements in a bigger environment makes this step unnecessary complicated.

    Is there a way to make a render script refresh itself automatically once the user has switched back to preview mode?

    Thank you for your help!

    • This topic was modified 5 years, 6 months ago by skalibran.
Viewing 1 replies (of 1 total)
  • Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    Thanks for the feedback! You guessed it right, the correct JS hook is the acfe/fields/flexible_content/preview action. You’ll also find variations, in case you need it:

    action('acfe/fields/flexible_content/preview',                                   response, $el, $layout, ajaxData);
    action('acfe/fields/flexible_content/preview/name=my_flexible',                  response, $el, $layout, ajaxData);
    action('acfe/fields/flexible_content/preview/key=field_123456',                  response, $el, $layout, ajaxData);
    action('acfe/fields/flexible_content/preview/name=my_flexible&layout=my_layout,  response, $el, $layout, ajaxData);
    action('acfe/fields/flexible_content/preview/key=field_123456&layout=my_layout', response, $el, $layout, ajaxData);
    

    As of your question regarding “refreshing a script” once a user edit a layout, the DOM and all JS code are already loaded into the browser at that time, so I’m not sure if that would be possible.

    There’s could be a way to remove/re-append the JS script files and force Javascript to re-execute them but that would require a huge amount of work and tests, as it could add bugs and compatibility issues. The most safe way to do it is by using the acf.addAction method.

    If you manage to achieve a working example of the delete/re-append/re-execute script files, feel free to share it tho, I would be curious to see it.

    Have a nice day!

    Regards.

Viewing 1 replies (of 1 total)

The topic ‘Automatic script reload when switching back to preview’ is closed to new replies.