You open my eyes, Anthony. Your ideas are excellent and I can put them to use without needing any structural change in web2py. I had not considered the fact that the comment field can contain HTML itself. I now have a lot to think about!
-- Joe B. On Wednesday, December 12, 2012 10:07:40 PM UTC-8, Anthony wrote: > > One option is to build it into the comment. The comment can be any > arbitrary HTML (which you can build with helpers), so the comment could > include the [?] icon with appropriate hover text, followed by the actual > comment. Another option is to create a custom > widget<http://web2py.com/books/default/chapter/29/07#Widgets> and > pass the help text as an argument to the widget function when specifying > the widget attribute of the field. > > If you create a custom formstyle function, as you suggest, one way to pass > the extra help content is by turning the "comment" attribute into a dict, > with a "help" key and a "comment" key: > > Field('myfield', comment=dict(comment='Fill in this field', help='More > detailed help...')) > > The formstyle function could then pull the comment and help content from > that dict to construct the field in the form. > > You can also do db.mytable.myfield.help = 'More detailed help...'. > > Anthony > > On Wednesday, December 12, 2012 11:43:29 PM UTC-5, Joe Barnhart wrote: >> >> I am working on a very form-heavy website that uses not only labels, >> controls, and comments, it needs extended mouseover help as well. The >> users comprises people who use the site infrequently, so I need to provide >> as much explanation for each field as I possibly can. The nice thing about >> the mouseover help is that I can create a small [?] icon somewhere on each >> field line which pops up paragraphs of help text if needed. The question >> is -- where to store it? >> >> Looking at Field, it seems like the ideal case would be to add an >> instance var "help" which could be initialized to "None". When needed, it >> could store some kind of "rich" string (which can have some simple >> formatting like bold face or italics for emphasis). While setting it in >> the Field is convenient, looking further at how the SQLFORM is generated >> from the Fields shows a real problem... >> >> The SQLFORM creates a list of 4-tuples which are passed to the >> "formstyle" factory that makes the HTML version of the form. There's no >> way I can add a 5th element to the tuple without breaking web2py. If we >> someday re-architect the web2py SQLFORM class, we might consider passing in >> a list of the Field objects directly to the formstyle factory so we never >> face this limit again. But for now I don't see any way to overcome this. >> >> All I can come up with is to generate the HTML tree for the form (in >> Python) and then use the access methods to manipulate it to add the help >> elements I want. It will be kind of messy and complicated but I can >> probably get it working. Or maybe I should do my own "formstyle" function >> and figure out a way to pass it a list of "help" text fields for the >> additional info. >> >> If anyone else has done something similar I'd love to hear about it. >> >> Joe B. >> >> --

