-
django-formset versions: 0.13.2 and 0.13.4. In several of the demo programs it is shown that using
will switch to a row-based layout. That is, a control's label is to the left of the control. When it comes to using a FormCollection, the template entry is limited to
with other class information provided through a renderer assigned to the default_renderer field of the form class. To that end I have the following arrangement:
While the contents of field_css_classes and label_css_classes make it into the rendered HTML, the content of control_css_classes does not. This prevents the control being shown next to the control. The control_css_classes content is mentioned in formset/templates/formset/bootstrap/field_group.html. It's absence from the rendered HTML suggests that either this file isn't being consulted for some reason or control_css_classes isn't being propagated as expected. Putting the extra CSS classes into the FormRenderer() in the FormCollection doesn't change things. Neither does the omission of the FormCollection's default_renderer assignment. I should note the presence of the fieldset_css_classes in the FormRenderer() instantiation. I have found that without form-flex in particular, the bootstrap classes such as mb-3 and col-sm-3 had no effect at all. That said, I'm not entirely convinced that form-flex is the correct thing to put here - it just happens to be an educated guess which seem to mostly work. Before digging any deeper into this, I was wondering whether I was missing something obvious. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
I'm not sure what is precisely going on here. But maybe I have a similar problem with 'default_renderer' in #43. |
Beta Was this translation helpful? Give feedback.
-
Further experimentation showed that the problem in my case was the use of the FieldsetMixin. To be honest I'm not sure why this was included in the definition of AddressForm. I suspect I saw it in an example somewhere and just copied it in. If the FieldsetMixin is not used, the template file utilised by the form by the bootstrap renderer is formset/bootstrap/form.html, which uses formset/bootstrap/field_group.html to render the fields. The latter explicitly references control_css_classes, which explains why control_css_classes takes effect when FieldsetMixin is not used. When FieldsetMixin is included, the template used is formset/default/fieldset.html. This in turn uses formset/default/field_group.html to render the form fields. The latter template makes no mention of control_css_classes, which explains why this doesn't take effect with FieldsetMixin included in the form class. Omitting FieldsetMixin also makes fieldset_css_classes ineffective, which takes out the form-flex class mentioned at the end of the initial comment. However, this didn't stop the bootstrap layout classes working. Thus without FieldsetMixin, the bootstrap layout classes are fully functional without form-flex being explicitly mentioned. The form_css_classes FormRenderer parameter is roughly equivalent to fieldset_css_classes when FieldsetMixin is not present. It can be used to place borders around the form, set margins and padding, and so on. While marking this as an answer to the initial question, I wonder whether the behaviour of the FieldsetMixin is as intended. As currently coded, the FieldsetMixin templates prevent some bootstrap layout options being used (such as row-based label-control pairs) when FieldsetMixin is included in a class derived from ModelForm. If this is an intended use case (which I was originally doing), the templates may need adjustment. Perhaps the formset/default/fieldset.html or formset/default/field_group.html templates need to be mapped to bootstrap-specific versions in renderers/bootstrap.py which propogate control_css_classes. If, however, FieldsetMixin is not designed to be used with ModelForm then all this is a moot point. This question could therefore be converted to an issue if FieldsetMixin is expected to work with ModelForm. |
Beta Was this translation helpful? Give feedback.
Further experimentation showed that the problem in my case was the use of the FieldsetMixin. To be honest I'm not sure why this was included in the definition of AddressForm. I suspect I saw it in an example somewhere and just copied it in.
If the FieldsetMixin is not used, the template file utilised by the form by the bootstrap renderer is formset/bootstrap/form.html, which uses formset/bootstrap/field_group.html to render the fields. The latter explicitly references control_css_classes, which explains why control_css_classes takes effect when FieldsetMixin is not used.
When FieldsetMixin is included, the template used is formset/default/fieldset.html. This in turn uses formset/default/f…