-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wagtail 2.13 compatibility #14
Conversation
Rendered widget output is now embedded in JSON within the data-block attribute, rather than directly on the page, and needs to be escaped accordingly
This provides a way for the data required to render the widget to be serialised and passed to Javascript, so it can be rendered and populated client-side and not just through a Django template.
This is built-in functionality of the WidgetWithScript utility class used by AdminChooser, and saves us having to include the initialisation JS in the template. Doing it this way means that we can call render_html from the StreamField logic to get just the HTML without the JS (and then trigger the JS at the right point in the StreamField lifecycle).
The standard widget rendering does not use this, as the call to create_instance_selector_widget ignores the return value. However, it will be used by the client-side component in the telepath implementation of StreamField: https://docs.wagtail.io/en/latest/reference/streamfield/widget_api.html
Just to add - wagtail-instance-selector's modal embeds are affected by wagtail/wagtail#7169, so if you test against the current 2.13 release candidates you may encounter JS errors on opening them... this will be fixed for 2.13 final. |
@markfinger Wagtail 2.13 is now out - https://github.com/wagtail/wagtail/releases/tag/v2.13 - would be great to have this reviewed and released out in the wild, if you have time. |
This looks amazing! Thanks @gasman! |
Thanks for all the work, @gasman. Sorry for the delay in response, I've been on leave. I've run a quick test against one of our wagtail 2.11 systems, and everything looks alright. |
Thanks again to everyone for the reports and the fixes. |
Fixes #11. The new telepath StreamField implementation in 2.13 requires some fairly heavy refactoring to the InstanceSelector widget, since InstanceSelector was quite heavily reliant on rendering a template for each instance, while StreamField needs to be able to construct them client-side from serialised data. I got it working by extracting an 'state' dict consisting of the pk, display_markup and edit_url, which can be used by both the server-side and client-side rendering logic.
(For reference, I submitted a fairly similar patch to wagtailmodelchooser that might help in following the changes: neon-jungle/wagtailmodelchooser#27)