'django crispy forms - add field help text?

Looking through the crispy forms I cannot find if help text is supported. im trying to add some help text to the select multiple field as per the below

Field('site_types', Title="Site Types", size="15", help_text="Hold down cmd on MacOS or ctrl on windows to select multiple"),

is this supported or would I use some other attribute to achieve this?

Thanks



Solution 1:[1]

Haven't used crispy forms in a little bit but I'm pretty certain you just define help_text like you would on a regular form. Looking at the docs, there are some additional configuration options for the help text if you happen to be using the Bootstrap template pack.

Solution 2:[2]

Rather than define help_text in crispy_forms.layout.Field, define it where you define choices (or use the solution by Pavan Kumar T S).

forms.py

from django import forms
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout, Field

SITE_TYPES = [
    ('business', 'Business'),
    ('education', 'Education'),
    ('entertainment', 'Entertainment'),
    ('news', 'News'),
    ('other', 'Other')
]

class TestForm(forms.Form):
    site_types = forms.MultipleChoiceField(
        choices=SITE_TYPES,
        help_text="Hold down cmd on MacOS or ctrl on windows to select multiple"
    )

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.helper.form_tag = False
        self.helper.layout = Layout(
            Field('site_types', Title="Site Types", size="15")
        )

Form:

Form with help text displayed below the field

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 William Shaw
Solution 2