On Tue, Sep 29, 2009 at 5:43 PM, cd34 <[email protected]> wrote:
>
> The very minimal controller you need to do the ToscaWidgets movie
> tutorial is:
>
>
>
> from pylons import request, response, session, tmpl_context
> from tw.mods.pylonshf import validate
> import tw.forms as twf
>
> from cp.lib.base import BaseController, render
>
> movie_form = twf.TableForm('movie_form', action='save', children=[
>    twf.HiddenField('id'),
>    twf.TextField('title'),
>    twf.TextField('year', size=4),
>    twf.CalendarDatePicker('release_date'),
>    twf.SingleSelectField('genera', options=['', 'Action', 'Comedy',
> 'Other']),
>    twf.TextArea('description', validator=twf.validators.NotEmpty),
> ])
>
> class TestController(BaseController):
>
>    def index(self):
>        tmpl_context.form = movie_form
>        return render('/movie.mako')
>
>   �...@validate(movie_form, error_handler='index')
>    def save(self, **kw):
>        return str(kw)
>
> and movie.mako would contain:
>
> ${tmpl_context.form()|n}
>
> Example taken from:
>
> http://toscawidgets.org/documentation/tw.forms/tutorials/index.html
>
> The page:
>
> http://toscawidgets.org/documentation/tw.forms/tutorials/validate_pylons.html
>
> contains an error in the validate string which is missing the quotes
> around the error_handler.
>
> @validate(form=movie_form, error_handler=index)
>
> should be replaced with:
>
> @validate(form=movie_form, error_handler='index')
> >
>


i use tw.forms, but I always found the validate decorator doesn't
necessarily fit my brain. However, you can fall back on
formencode/htmlfill which is what the validator wraps up for you. It's
not that much more code.

http://pylonsbook.com/en/1.0/working-with-forms-and-validators.html#introducing-formencode

give that a shot.




-- 
Thomas G. Willis

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" 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/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to