Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make form labels and fields display on the same line in django-crispy-form

class CustomerRegistrationForm(forms.Form):

    def __init__(self, *args, **kwargs):
        self.helper = FormHelper()
        self.helper.form_action = 'customer_register'


        self.helper.layout = Layout(
            HTML("""<h3>Create new customers account</h3>"""),
            Row(Field('first_name',),),
            Field('last_name',),
            Field('gender',),
            Row( Field('gender'),),
        )

The result from this class is like the fields are underneath of the labels, but I want to have something like the example of https://github.com/maraujop/django-crispy-forms, where the labels and fields are in the same line.

What did I miss?

like image 522
user1446870 Avatar asked Oct 27 '25 15:10

user1446870


1 Answers

If you are using the default template pack (Bootstrap) you have to assign the class form-horizontal to your form tag.

Float left, right-aligned labels on same line as controls

Either do it in your template or use your form.helper as demonstrated in the example gist for crispy-forms:

helper.form_class = 'form-horizontal'
like image 128
arie Avatar answered Oct 29 '25 06:10

arie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!