OriginalBrownster wrote:
> Hi
>
> I want to know how to implement the following source code and template
> sample they gave within the widget browser.
>
>
> I reviewed over the checkbox widget, and I think it will be easier
> using the widget than creating my own form in my template.
>
> I am assuming this is supposed to go in the controller
>
>
> class CheckBoxListDesc(CoreWD):
> name = "CheckBox List"
> for_widget = CheckBoxList("your_checkbox_list",
> options=[(1, "Python"),
> (2, "Java"),
> (3, "Pascal"),
> (4, "Ruby")],
> default=[1,4])
>
> and this in the template
> <ul xmlns:py="http://purl.org/kid/ns#"
> class="${field_class}"
> id="${field_id}"
> py:attrs="list_attrs"
> >
> <li py:for="value, desc, attrs in options">
> <input type="checkbox"
> name="${name}"
> id="${field_id}_${value}"
> value="${value}"
> py:attrs="attrs"
> />
> <label for="${field_id}_${value}" py:content="desc" />
> </li>
> </ul>
>
>
> However I get a traceback error
>
> Traceback (most recent call last):
> File "/var/projects/document_site/se/start-se.py", line 27, in ?
> from se.controllers import Root
> File "/var/projects/document_site/se/se/controllers.py", line 75, in
> ?
> class CheckBoxListDesc(CoreWD):
> NameError: name 'CoreWD' is not defined
>
>
>
> I need alot of help with this. I've been trying to use checkboxs within
> my application but I have had NO SUCCESS. If someone is willing to help
> me out it would be greatly appreciated.
>
> Thank you
> Stephen
Hi Stephen,
I will show you how to build a complete form containing even a
CheckBoxList, in your controller do something like this:
from turbogears import expose, validate, error_handler, flash, widgets,
validators
class MyFields(widgets.WidgetsList):
name = TextField()
email = TextField(validator=validators.Email())
language = CheckBoxList(options=[(1, "Python"), (2, "Java"), (3,
"Pascal"), (4, "Ruby")],
default=[1,4])
my_form = widgets.TableForm(fields=MyFields(), action="save")
now you need two methods methods attached to your controller in this
way:
@expose(template="test.new")
def new(self, tg_errors=None):
if tg_errors is not None:
flash("Please fix all errors")
return dict(my_form=my_form)
@expose()
@validate(form=my_form)
@error_handler(new)
def save(self, name, email, language):
#the data your received is valid and you can add it to the database
...
Hope this helps, keep in mind that when you look at a widget using the
widget browser the source code refers to the code running that example,
generally what you really need is the for_widget portion, the template
tab refers to the widget's template for further customization that
oftten is not needed.
Inside the turbogears's trac you can find a complete package that shows
how to use widgets (very easy example anyway), I have updated it to
work with the latest turbogears version (0.9a8), you can find it here:
http://trac.turbogears.org/turbogears/attachment/wiki/SimpleWidgetForm/FormsTutorial-0.9a8.tar.bz2?format=raw
Ciao
Michele
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/turbogears
-~----------~----~----~----~------~----~------~--~---