I’m trying to create a form layout with a few fields that are of a different size than the other fields. What is the best way to do this using crispy-forms? For example, I’m laying out the form in rows where most of the rows have two fields but occasionally a single field will occupy the whole row.
--------------------------------------------------
| First Name | Last Name |
--------------------------------------------------
| User Name | Email |
--------------------------------------------------
| Bio |
--------------------------------------------------
In the example layout above, each field is composed of a label and the text input in the actual HTML (I just didn't know how to show this in the question). I’m using Bootstrap 3 so on the first two lines I want the labels to have a class of ’col-sm-2’ and the input fields to have a class of ‘col-sm-4’ so that when rendered, they show up with two fields per row (i.e. 12 columns). However, for the third row with the “Bio” field, I want the input field to be “col-sm-10’ to take up the whole row.
Here is some sample code that is close enough that someone may be able to help.
self.helper = FormHelper(self)
self.helper.form_tag = False
self.helper.form_class = 'form-horizontal'
self.helper.label_class = 'col-sm-2'
self.helper.field_class = 'col-sm-4'
self.helper.layout = Layout(
MultiField(
'Profile Information',
Div('first_name', 'last_name'),
Div(css_class='clearfix'),
Div('username', 'email'),
Div(css_class='clearfix'),
Div('bio', css_class='col-sm-10'),
),
)
I’ve tried using several different combinations of Div, Field, and Row and using combinations css_class and wrapper_class as well as trying to create "custom" attributes but nothing works to give me the layout that I want. I’ve even tried several different combinations of nested Div(Field) type structures but nothing worked.
There doesn’t seem to be a way to dynamically change the helper.field_class for just the “Bio” field row. It seems really wrong to resort to using the HTML method but that’s all I can think to do for this as this point.
What is the right way to do this using crispy-forms?