blueFast
blueFast

Reputation: 44461

Avoid display of help_text in django crispy forms

I am customizing the RegistrationForm from django-registration-redux with django-crispy-forms. For that I have defined a FormHelper which is working fine:

class MyRegistrationForm(RegistrationForm):

    def __init__(self, *args, **kwargs):
        super(MyRegistrationForm, self).__init__(*args, **kwargs)
        helper = self.helper = FormHelper()
        # Moving field labels into placeholders
        layout = helper.layout = Layout()
        for field_name, field in self.fields.items():
            layout.append(Field(field_name, placeholder=field.label))
        helper.template_pack = 'bootstrap3'
        helper.form_show_labels = False

My form is shown as I want: no labels, bootstrap3 and placeholders derived from label.

Now I would also like to suppress the help_text, which is coming from the Field definition. There is a somehow related flag here (help_text_inline), but that is not intended to disable the display of the help text. I can not find a flag to completely disable the display of the help text in the FormHelper documentation. Is this at all possible?

Removing the help text from the Field definition is not really an option, since I am inheriting the RegistrationForm and I do not want to modify it too much.

Upvotes: 2

Views: 3037

Answers (1)

RootRooster
RootRooster

Reputation: 11

The code below should do the trick.

def __init__(self, *args, **kwargs):
    ...
    for field_name, field in self.fields.items():
        self.fields[fieldname].help_text = None
    ...

The solution is inspired by this answer here.

Upvotes: 0

Related Questions