jazzband / django-floppyforms

Full control of form rendering in the templates.
http://django-floppyforms.readthedocs.org/
Other
841 stars 148 forks source link

on bootstrap3 support #86

Closed avoine closed 10 years ago

avoine commented 10 years ago

I've tried to make floppyform to work with bootstrap3. After minor modifications to the templates, I realized that every input widget needed the "form-control" class.

So I naively patch the Input.get_context method in widgets.py to add this simple code:

    if 'class' in context['attrs'].keys():
        context['attrs']['class'] += " form-control"
    else:
        context['attrs']['class'] = "form-control"

Then, I needed something to apply does changes to the modelForms. But because of how Django handled modelForm it was not easy. Fortunately, I found that code to me help out:

https://github.com/pydanny/django-admin2/blob/develop/djadmin2/forms.py

But I still need to do something like:

Class MyForm(forms.ModelForm): ....

MyForm = floppify_form(MyForm)

So I was wondering if there is something that could be done to make bootstrap3 simpler. (Note: the modelForms problem might be better in an other issue...)

avoine commented 10 years ago

i guess a less naive way to add form-control is via attrs.html:

{% if "class" in attrs.keys %}
{% for name, value in attrs.iteritems %} {{ name }}{% if name == "class" %}="form-control {{ value }}"{% if value != True %}="{{ value }}"{% endif %}{% endif %}{% endfor %}
{% else %}
{% for name, value in attrs.iteritems %} {{ name }}{% if value != True %}="{{ value }}"{% endif %}{% endfor %} class="form-control"
{% endif %}
gregmuellegger commented 10 years ago

Hi, I think if you want to use bootstrap3 you can use the following package: https://github.com/grundleborg/django-floppyforms-bootstrap3