#35881: MultiWidget bypasses subwidget rendering customization ------------------------------+-------------------------------------- Reporter: Adam Johnson | Type: Bug Status: new | Component: Forms Version: dev | Severity: Normal Keywords: | Triage Stage: Unreviewed Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 ------------------------------+-------------------------------------- [https://docs.djangoproject.com/en/stable/ref/forms/widgets/#django.forms.Widget.render Widget.render] is documented as the place to override rendering behaviour, with the top of `Widget` docs saying:
> You may also implement or override the render() method on custom widgets. On top of this, the [https://docs.djangoproject.com/en/stable/ref/forms/renderers/#the-low- level-render-api renderer API] is touted as another way to customize how widgets are rendered. `MultiWidget` bypasses both of these for its subwidgets. Rather than go through their `render()` methods, it uses a template that just includes the subwidget templates: {{{ {% spaceless %}{% for widget in widget.subwidgets %}{% include widget.template_name %}{% endfor %}{% endspaceless %} }}} I encountered this issue on a project with custom templates, where a MultiValueField from a third-party package dropped the custom styles. One solution could be to make a `MultiWidget.render()` method that calls each subwidget's `render()` method and glues the results together. Another would be to make the existing `MultiWidget.get_context` pass each subwidget's render method into the context, and then the template could call it. One backwards compatibility concern is continuing to work if the user has customized `multiwidget.html`, where they may be relying on the old context data and using `{% include subwidget.template_name %}`. -- Ticket URL: <https://code.djangoproject.com/ticket/35881> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/django-updates/01070192ebc6da83-3ec9610b-21eb-47f5-854c-76eda707de85-000000%40eu-central-1.amazonses.com.