Guess formstyle from the widget code

31 views
Skip to first unread message

Bruno Rocha

unread,
Aug 23, 2011, 11:31:57 PM8/23/11
to web2py-developers, Massimo Di Pierro
Hi,

I am coding a patch to add LABEL(for-...) to Radio, Checkbox and Upload Fields in sqlhtml.py

Today, this widgets uses <TABLE> to render, but it is not good because we can have FORMSTYLE = 'divs' or 'ul'

I am thinking about some options.

A way to check formstyle from the widget? (is there?)

Include a global setting to check. i.e if ...settings.widget_style = 'divs'

Or (the better option IMO) include a new attribute to Field. Field.widget_style

so we can check for field.widget_style from the widget and render as 'div', 'ul' or the default <table> (to not break anything)

Any ideas?


Custom widgets with LABEL(for=)



--
Bruno Rocha

Massimo Di Pierro

unread,
Aug 23, 2011, 11:35:52 PM8/23/11
to Bruno Rocha, web2py-developers
I need to think about this. Let's here some more opinions meanwhile.

Anthony

unread,
Aug 23, 2011, 11:52:03 PM8/23/11
to web2py-d...@googlegroups.com, Massimo Di Pierro
I notice that many of the widgets take **attributes, but I don't think there is an (easy) way to pass arguments to the widget in Field(..., widget=...). It might be nice to be able to do so, in which case, maybe the relevant widgets could take a 'style' argument. Could still be helpful if they adopt the style of the form by default.
 
Anthony

Martín Mulone

unread,
Aug 24, 2011, 6:35:38 AM8/24/11
to web2py-d...@googlegroups.com
Using lambda to customize it, this an idea how can be coded

Table:

render_fieldzone = lambda label, value, comment: TR(TD(label),TD(value),TD(comment))
render_tablezone = lambda fields: TABLE(fields) 

UL:
render_fieldzone = lambda label, value, comment: LI(LABEL(label),value,comment)
render_tablezone = lambda fields: UL(fields) 

DIV:
render_fieldzone = lambda label, value, comment: DIV(DIV(label,_class='fieldlabel'),DIV(value,_class='fieldvalue'),DIV(comment,_class='comment'),_class='fieldrow')
render_tablezone = lambda fields: DIV(fields) 

for dbfield in dbfields:
fields.append(render_fieldzone(dbfield.label, dbfield.value, dbfield.comment))

2011/8/24 Anthony <abas...@gmail.com>
--
mail from:GoogleGroups "web2py-developers" mailing list
make speech: web2py-d...@googlegroups.com
unsubscribe: web2py-develop...@googlegroups.com
details : http://groups.google.com/group/web2py-developers
the project: http://code.google.com/p/web2py/
official : http://www.web2py.com/



--

Massimo Di Pierro

unread,
Aug 24, 2011, 10:42:15 AM8/24/11
to Bruno Rocha, web2py-developers
If you send this patch, I missed it.

On Aug 23, 2011, at 10:31 PM, Bruno Rocha wrote:

Reply all
Reply to author
Forward
0 new messages