jazzband / django-floppyforms

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

MultiValueField and bound_field #108

Open lucalenardi opened 10 years ago

lucalenardi commented 10 years ago

I'm having hard times trying to figure out how to use the formfield tag with a MultiValueField.

We have a custom subclass of a MultiValueField (let's call it DoubleValueField) with its custom widget DoubleWidget. The DoubleValueField has two ChoiceField inside.

The problem is that, in templates, the template tags are ignoring the following call: {% formconfig field using "discover/floppyforms/select.html" for "DoubleWidget" %}. Thus, rendering doesn't even get to the required template for the two subfields.

Trying to iterate over the subfields and calling {% formfield field with ... %} over them, rises an AttributeError, because those fields are, actually, not bound_fields.

It should be possible to map MultiValueField subfields to the correct floppyform template for rendering. Am I missing something here?

Thanks!

gregmuellegger commented 10 years ago

Before I go deeper into this, it might be worth checking if you made sure that use floppyform's widget class for the ChoiceField. So did you assign the floppyforms.fields.ChoiceField inside the DoubleValueField or did you use django's django.forms.fields.ChoiceField?

Otherwise I'm not yet to familiar with the MultiValueField class. So a code example showing what you currently have might be useful to try recreating your issues.

Also, you might be interested in the implementation of floppyform's SplitDateTimeWidget and SelectDateWidget widgets in widgets.py. They kind of implement what you want, but using one widget with two input fields instead of one field with two widgets.

After all this might be a bug in floppyforms. I just figured that we don't have any tests for floppyforms.fields.MultiValueField. So let's investigate more on your issue.

lucalenardi commented 10 years ago

Thank for the reply. Sure, we are using the ChoiceField from floppyforms, which, by default instantiate a Select widget.

The problem is that the MultiWidget by itself does nothing, it just pass over to the parent class form Django. So, the template and render part of floppyforms should be re-written for every MultiWidget subclass. That is a part of what SelectDateWidget does, if I'm understanding it right.

It could be useful to have a sort of more abstract render method in the MultiWidget class, that takes a template or tries to load the default sub-widget templates with their related context.