Dan Jacob, el lunes 19 de diciembre a las 23:30 me escribiste:
> I've just finished writing and testing some new widgets, including a
> RadioButtonList and Checkbox list. One thing came to mind with these
> widgets and the SelectField widgets:the option list may need to be
> created dynamically (e.g. during template insertion). I thought it
> would be a good idea for the "options" argument to be either a list of
> tuples(value, text, optional attrs) or a function returning same:
>
> def get_categories():
> return [(cat.id, cat.name) for cat in model.Category.select()]
>
> s = SelectField("categoryID", labeltext="Choose a category",
> options=get_categories, validator=IntValidator())
>
> c = CheckBoxList("categories", options=get_categories,
> validator=ForEach(IntValidator()))
What's the problem with:
s = SelectField("categoryID", labeltext="Choose a category",
options=[(cat.id, cat.name) for cat in model.Category.select()],
validator=IntValidator())
?
> The "selected" or "checked" attributes are automatically set if they
> match the input value(s).
And what about grouping RadioButtonList with SelectField and CheckBoxList
with MultipleSelectField? After all they are used for the same thing
(selecting only one item from a list and selecting multiple items from a
list respectively), they just differ in how the lists are presented.
Maybe you can add a parameter to render() to choose what to use in the
template, like:
<div py:replace="selectField.render(style='radiobuttons')">
<div py:replace="selectField.render(style='list')">
<div py:replace="multipleSelectField.render(style='checkboxes')">
<div py:replace="multipleSelectField.render(style='list')">
(maybe the kid templates is wrong, I didn't have the time yet to play with
kid, but I think you'll get the idea =)
--
Leandro Lucarella (luca) | Blog colectivo: http://www.mazziblog.com.ar/blog/
.------------------------------------------------------------------------,
\ GPG: 5F5A8D05 // F8CD F9A7 BF00 5431 4145 104C 949E BFB6 5F5A 8D05 /
'--------------------------------------------------------------------'
Ah, se va en 1981? Pero por qué? ... Ah, porque ya había sido determinado,
entonces quiere decir que pronto vamos a elegir presidente nuevo nosot...
Ah, nosotros no? Ah, lo van a elegir en la ... Ah! Quiere que le diga? Muy
bien pensado, porque cada vez que lo elegimos nosotros no duran nada!
-- Tato vs. Tato (1980, Gobierno de Videla)