question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Remove individual label from django crispy form layout

See original GitHub issue
    self.helper = FormHelper()
    self.helper.form_method = 'POST'
    self.helper.form_class = 'form-horizontal'
    #self.helper.form_show_labels = False
    self.helper.show_label_first_name = False
    self.helper.layout = Layout( 
        Div(
                 Div(HTML("""<label> Trust Admin Name</label>""")),
            Div(Field('first_name',label="", placeholder="First Name"), css_class='span3'),
            Div(Field('middle_name', label="", placeholder="middle Name"), css_class='span3'),
            Div(Field('last_name', label="", placeholder="last Name"), css_class='span3'),
            ),         
        Div(
            Div(Field('mobile_number', placeholder= "Mobile Number"), css_class='span6'),
            Div(Field('landline_number',placeholder="Landline Number"), css_class='span6'),
            ),
        Div(
            Div(Field('email', placeholder="Email Address"), css_class='span6'),
            Div('', css_class='span6'),
            ),
        )
    super(TrustAdministrationForm, self).__init__(*args, **kwargs)

I want to remove the “first_name”, “middle_name” and “last_name” from form layout, How ca i do this.

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

12reactions
notanumbercommented, Nov 26, 2013

In case you (or someone else) hasn’t figured out how to do this:

def MyForm(forms.Form):
    def __init__(self, *args, **kwargs):
        super(MyForm, self).__init__(*args, **kwargs)
        self.fields['my_field'].label = False

        # ...helper stuff, other stuff, etc...
6reactions
PabloVallejocommented, Nov 3, 2015

@notanumber, thanks it’s working for us. 👍

for field_name in self.fields:
    field = self.fields.get(field_name)
    field.widget.attrs['placeholder'] = field.label
    field.label = ''
Read more comments on GitHub >

github_iconTop Results From Across the Web

Remove Labels in a Django Crispy Forms - Stack Overflow
The solution below lets you remove a label from both a regular or crispy control. Not only does the label text ...
Read more >
Removing labels from dynamic django crispy formset
I have taken your advice and switched to using a helper, and have been able to remove the labels using form_show_labels = False...
Read more >
Layouts — django-crispy-forms 1.14.0 documentation
Django -crispy-forms defines another powerful class called Layout , which allows you to change the way the form fields are rendered.
Read more >
django-crispy-forms Documentation - Read the Docs
These are layout objects that are not specific to a template pack. We'll go one by one, showing usage examples: • Div: It...
Read more >
Django Tutorial Part 9: Working with forms - MDN Web Docs
The Form class is the heart of Django's form handling system. It specifies the fields in the form, their layout, display widgets, labels, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found