Skip to content

Conversation

amjoconn
Copy link

I am using a bootstrap form mixin which includes code similar to this

class BootstrapForm(object):
    def __init__(self, *args, **kwargs):
        super(BootstrapForm, self).__init__(*args, **kwargs)
        for bfield in self:
            field = self.fields[bfield.name]
            classes = ['form-control']
            if 'class' in field.widget.attrs:
                classes.append(field.widget.attrs['class'])
            field.widget.attrs.update(
                {'class' : ' '.join(classes)}
            )

It depends on the value of field.widget.attrs['class'] being propagated to the rendered widget.

One could argue that Django should be doing the combining for us, but it doesn't, for now this works, and I don't believe will cause any other issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants