3

I want to add help text to my forms. However, I want it to appear as a small question mark icon to the right of the input box, when clicked on, will show the help_text.

I have a way of doing it through the html, but when I have more than one field with help_text, its gets buggy.

Main question, anyway of doing this using Django and not the html? If so, what would the steps be to implement?

Thanks

César
  • 9,939
  • 6
  • 53
  • 74

1 Answers1

3

You could create a templatetag, something along these lines should work (untested)

@register.simple_tag
def render_help_text(field):
    if hasattr(field, 'help_text'):
        return mark_safe(
            "<a><img src='/static/img/icons/help.gif' title='{help_text}' /></a>".format(**{'help_text': field.help_text})
        )
    return ''

template

{% for field in form %}
    <!-- other stuff -->
    {% render_help_text field %}
{% endfor %}
Hedde van der Heide
  • 21,841
  • 13
  • 71
  • 100
  • That was a round about way, but still worked. I ended up just putting title='{{ help_text }}' in the image tag. You gave me the idea though, or well pointed it out! :D thanks! – Jake Suding May 30 '13 at 12:08