I would say use the same name as that way, cherrypy give you a list.
Then write a custom schema/validator that validate the list form or use
some helper programs to loop through it against a simple validator.

I still think validation should not be a feature provided by the
framework and this feeling grows stronger as my apps evolve. For simple
CRUD like page, it may work(even that is not a given) but anything
involves some process logic and user friendliness, the framework based
validation can be thrown out.

Andy Dustman wrote:
> Kevin Dangoor wrote:
> > On 10/6/05, Yesh <[EMAIL PROTECTED]> wrote:
> > >
> > > Thanks for the reply.  I did read the SQLObject docs and the Kid
> > > template. I was using Cheetah before.
> > >
> > > What I would like to know is how to name
> > > the form variables for the invoice items so that I can commit it
> > > automatically.
> >
> > Using CherryPy, you can name the variables the same and then you'll
> > get lists in. For example,
> >
> > <input type="text" name="foo" py:for="foo in foos"/>
> >
> > Will give you an input field for each item in the list. In your
> > controller method:
> >
> > def updatefoo(self, foo):
> >     if not isinstance(foo, list):
> >         foo = [foo]
> >     for i in range(0, len(foo)):
> >         do whatever it is you do with foos
> >
> > The thing to watch out for is checkboxes, because the browser doesn't
> > send a value for unchecked checkboxes.
> >
> > I just thought I'd point this out in case it works better for you for
> > this particular problem. The FormEncode route should work well as
> > well.
>
> That's one problem I'm trying to solve now: I have a list of
> checkboxes, using ids pulled from a table, and I need to figure out the
> best way to encode these. My first attempt was to give each checkbox
> the same name (audience, in this case) and make value=id. This works if
> I don't have a validator, because the problem is, if multiple
> checkboxes are selected, I get a list, but if only one is selected, I
> get a single item (string).
>
> So I did some digging and found the variabledecode stuff, and changed
> my template so the checkboxes were named audience-${id}. However, it's
> not obvious how to invoke variabledecode so that my method gets a
> parameter called audience that is a list. Right now, it sees
> audience-1, audience-2, etc. as keywords parameters (theses are being
> caught as **kwargs).
>
> What's the best/right way to solve this? It there some decorator
> function to put ahead of @expose that will pre-filter arguments with
> variabledecode?

Reply via email to