Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get two fields inline in django-crispy forms but not others horizontal?

I want to have two fields corresponding to check boxes next to next (not one below other) like I have shown in the image.

my form inherits from models.Form and has other fields, which I have left out here. is it possible to get this using crispy-forms? For rest of the fields,

I use self.helper.form_class='form-horizontal', which I want to keep intact for other form fields

Thanks

enter image description here

like image 686
brain storm Avatar asked Apr 11 '14 20:04

brain storm


2 Answers

This is untested but I think this will work.

self.helper.layout = Layout(
    Div(
        Div('inlineField1',css_class='col-md-6',),
        Div('inlineField2',css_class='col-md-6',),
        css_class='row',
    ),
    'other_fields',
    ...,

    FormActions(
        Submit('submit', 'Submit'),
    ),
)
like image 71
Tim Avatar answered Sep 29 '22 18:09

Tim


Layout helper with bootstrap can do this:

form.py

self.helper.layout = Layout(
Row(
    Column('check_1', css_class='form-group col-md-2 mb-0'),
    Column('check_2', css_class='form-group col-md-2 mb-0'),
    css_class='form-row'
),

Template

{% block content %}
{% crispy form %}
{% endblock %}
like image 24
ian Avatar answered Sep 29 '22 18:09

ian