Helptext forms forms

29 views
Skip to first unread message

4 The good Life we work

unread,
Dec 14, 2012, 9:01:56 AM12/14/12
to django...@googlegroups.com
Hallo,
I'm wondering if there is a better way to have helptext informs than
help_text which is displayed under the form.
Something like FIEDL ? while ? is a button I can click on and it
displays the helptext.

I'll welcome an example.

Thanks,
Tony

Chris Cogdon

unread,
Dec 14, 2012, 2:45:40 PM12/14/12
to django...@googlegroups.com, 4theg...@googlemail.com
If you're designing your own HTML (eg: this is not in the admin) then there's nothing stopping you rendering the help text any way you want. Eg:


{{ form.field1 }}<img src="questionmark.gif" onclick="showpopuphelp('{{ form.field1.help_text }}');return false;" />

(that might not exactly work as written, but using it to give you the gist of things... my preference would be to put the text into a <span class="fieldhelp> and use jQuery magic to wrap it up)

If you were doing this a lot, and would prefer to stick with using {{ form.as_table }} (for example) and rely on the default HTML generators for each field, then you'll need to create your own widgets, probably inheriting from the standard widgets, and override the html generators.


If you wanted to change how the fields were being displayed in the ADMIN, then that will require overriding the field widgets in the ModelAdmin's with your own widgets created the same way above.

4 The good Life we work

unread,
Dec 14, 2012, 4:52:27 PM12/14/12
to Chris Cogdon, django...@googlegroups.com
Hallo Chris,

thank you for the good explanation.
I'm then afread that I have to create my own widget for this. Can you
support me on this?

Thanks,
Tony Michael

Chris Cogdon

unread,
Dec 14, 2012, 6:51:26 PM12/14/12
to django...@googlegroups.com, Chris Cogdon, 4theg...@googlemail.com
"Support": sure! I won't "do the work" for you though :)

Okay, Just reading through the django code, and I'm seeing that the help_text is _not_ emitted in the field's widget, but in the _html_output method of BaseForm In other words, you don't need to update the widget. Useless doing so.

So, to ask about the options above, do you want to override the behaviour of the admin, or your own code?

Do you use this often enough that you'll want to change the behaviour of as_p, as_table or as_ul, or are you happy to just take control of things on that side, yourself?

The standard behaviour is to put the help text into <span class="helptext">xxx</span> ... its perfectly possible to use jQuery to replace all of those instances with whatever HTML you want.


So... which route is going to get you what you need ?
Reply all
Reply to author
Forward
0 new messages