Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add an easy API in the templates to add a class to an input element. #99

Open
1 task
gregmuellegger opened this issue Mar 31, 2014 · 3 comments
Open
1 task

Comments

@gregmuellegger
Copy link
Collaborator

This issue was brought up recently by #86 and is quite a basic use case. So we need to come up with:

  • an API how to add classes to form widgets.
@benoitbryon
Copy link

A naive implementation could use {{ extra_classes }} context data in templates/floppyforms/attrs.html. Something like that:

{{ name }}{% if value|stringformat:"s" != "True" or value != 1 %}="{{ value }}{% if name == "class" %} {{ extra_classes }}{% endif %}"

Then what about {% widget %} accepting options such as using and with? It would make it easy to provide custom context data and to use alternative templates for widgets.

Another option would be to update field's attrs dictionary (or a copy of it)... but, right now, I do not have a nice idea about how to do it in a simple an safe way.

@treyhunner
Copy link
Member

You could implement this similarly to the rend_field tag or add_class filter in django-widget-tweaks.

@eagle-r
Copy link

eagle-r commented Nov 3, 2014

Is there anything happening on this issue in the near future or is there a recommended workaround?

Our project calls for Bootstrap3 and we're running into this very issue. I've looked at #86 and unfortunately https://github.com/grundleborg/django-floppyforms-bootstrap3 is only a partial implementation.

I tried creating a Bootstrap layout based on the one in the docs with a modified version of attrs.html but my layout doesn't seem to be ignoring that template for some reason. Is there a formconfig that I need to use to get it to reference my attrs.html rather than the standard one?

I've also tried adding the CSS class via the with option for the formfield tag but that doesn't seem to be passed through either.

Any other suggestions? Thanks.

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

No branches or pull requests

4 participants