-
Notifications
You must be signed in to change notification settings - Fork 62
Description
Hello,
As the title suggests, when rendering a multiwidget, classes are not applied to the subwidgets.
The cause is the following:
In https://github.com/django-crispy-forms/crispy-tailwind/blob/main/crispy_tailwind/templatetags/tailwind_field.py, in the CrispyTailwindFieldNode.render
method, we're iterating over the widgets but trying to get the css-class for the widgets of the field. This works fine when the field's widget has no subwidget (CharField, etc), but not for a MultiWidget.
for widget, attr in zip(widgets, attrs):
...
if template_pack == "tailwind" and '"class"' not in attr.keys():
css_container = context.get("css_container", self.default_container)
if css_container:
css = " " + css_container.get_input_class(field)
css_class += css
It's always the parent field which is passed to css_container.get_input_class
.
in get_input_class
, we get the name of the widget linked to the field:
def get_input_class(self, field):
widget_name = re.sub(r"widget$|input$", "", field.field.widget.__class__.__name__.lower())
return getattr(self, widget_name, "")
widget_name
will be equal to multi
which, in turn does not return any css class for the subwidget.
I have found the workaround and will open a PR in the meantime so we can discuss it there.