jrief / django-formset

The missing widgets and form manipulation library for Django
https://django-formset.fly.dev/
MIT License
317 stars 30 forks source link

Not possible to set custom classes on input fields with the tailwind renderer #118

Open boosh opened 6 months ago

boosh commented 6 months ago

Hey, I found an issue trying to set custom classes on widgets.

The renderer overwrites classes declared on a widget, making it impossible to do this:

    my_button = forms.CharField(
        label="",
        widget=forms.widgets.TextInput(
            attrs={
                "type": "button",
                "value": "Configure",
                'class': 'btn-configure',     # never included in the class attribute
            }
        ),
    )

Fields should add to any existing attributes instead of replacing them.

jrief commented 5 months ago

You must override the class FormRenderer. Simply inherit from formset.renderers.tailwind.FormRenderer and override the method to add the CSS class, aka. _amend_text_input().