Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Allow css classes to come from self.attrs without being overwritten. #39

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

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.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants