Using help tooltips/passing arguments to TW2 form widget

69 views
Skip to first unread message

Juraj Variny

unread,
Oct 9, 2012, 6:40:56 AM10/9/12
to sp...@googlegroups.com
Hi, I want to add help tooltips to AddRecordForm. Tried following without any effect, help texts show as plain text:


class OrderForm(formbase.AddRecordForm):

..etc..

hover_help = True

#__widget_args__ = {'hover_help' : True} #nope, causes exception

__base_widget_args__ = {'hover_help' : True}

reqAmount = TextField('reqAmount',validator=IntValidator(required=True,min=1),size=15, help_text='Please enter quantity of items you want to buy or sell.')


Later, I want to use more fancy tooltips, then how do I set the underlying tw2 widget template?


Juraj


Alessandro Molina

unread,
Oct 11, 2012, 4:48:14 AM10/11/12
to sp...@googlegroups.com
Sorry for the late answer,
If you are using TW2 you should be able to specify
{'attrs':{'title':'My Help String'}} the browser should then display
it as over text.
> --
> You received this message because you are subscribed to the Google Groups
> "sprox" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/sprox/-/szTxLNXLa9AJ.
> To post to this group, send email to sp...@googlegroups.com.
> To unsubscribe from this group, send email to
> sprox+un...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/sprox?hl=en.

Alessandro Molina

unread,
Oct 11, 2012, 6:02:48 PM10/11/12
to sp...@googlegroups.com
On Thu, Oct 11, 2012 at 10:48 AM, Alessandro Molina
<alessand...@gmail.com> wrote:
> Sorry for the late answer,
> If you are using TW2 you should be able to specify
> {'attrs':{'title':'My Help String'}} the browser should then display
> it as over text.
>

Just to be more precise.

If you use __field_widgets_args__ you should use {'myfieldid':
{'attrs':{'title':'My Help String'}}} otherwise you can use
__field_attrs__ and in that case just set {'myfieldid':{'title':'My
Help String'}}.

Juraj Variny

unread,
Oct 11, 2012, 6:04:14 PM10/11/12
to sp...@googlegroups.com
Thanks Alessadro, but you did not say anything about customizing tw2 template. Fortunately I figured it out, so for reference: To modify how HTML for form table rows(including help texts) is generated in TW2, one should not modify TableForm template, but its child TableLayout instead. So I hacked together following:

class OrderForm(formbase.AddRecordForm):

class mytableform(tw2.forms.TableForm):

class mytablelayout(tw2.forms.TableLayout):

#table_layout.html or table_layout.mak copied from TW2 and customized

template = 'myproject.templates.table_layout'

child = mytablelayout

#tell sprox to use mytableform instead

__base_widget_type__ = mytableform

#sprox business as usual

__model__=Order


One caveat: when using Turbogears, I found that the table_layout template is not reloaded when app is reloaded.

Juraj


Dňa štvrtok, 11. októbra 2012 10:48:15 UTC+2 Alessandro Molina napísal(-a):

Juraj Variny

unread,
Oct 11, 2012, 6:13:47 PM10/11/12
to sp...@googlegroups.com

Tried to fix formatting:

class OrderForm(formbase.AddRecordForm):

class mytableform(tw2.forms.TableForm):

class mytablelayout(tw2.forms.TableLayout):

#table_layout.html or table_layout.mak copied from TW2 and customized

template = 'myproject.templates.table_layout'

child = mytablelayout

#tell sprox to use mytableform instead

__base_widget_type__ = mytableform

#sprox business as usual

__model__=Order



Dňa piatok, 12. októbra 2012 0:04:14 UTC+2 Juraj Variny napísal(-a):

Alessandro Molina

unread,
Oct 11, 2012, 6:15:29 PM10/11/12
to sp...@googlegroups.com
Ahh, you wanted to add custom tooltips and not use the browser standard one.
Sorry, missed that part, I supposed you just wanted the plain ones.

Yes, in that case you need to use custom templates, keep in mind that
TW2 makes possible to pass templates as an argument, so you can use
custom templates even with __field_widget_args__ withouth having to
subclass.
> https://groups.google.com/d/msg/sprox/-/r-crZxmJbngJ.
Reply all
Reply to author
Forward
0 new messages