Thanks, the missing name in the fieldset was the problem.

Now I'm puzzled from another validation issue. I use the get_errors()
function from
http://tinyurl.com/3236pt and it works fine in general, except one
case where I try to validate another irrelevant field. It's easier to
explain in code:

class SomeController(tg.controllers.Controller):

    @tg.expose(template=some_template)
    # @tg.validate(validators={"id": validators.Int()})
    def edit(self, id, **kwds):
        tg_errors,kwds = get_errors(self, some_form, **kwds)
        if tg_errors:
            return dict(form=some_form)
        # process the validated submitted form here

where get_errors is:

def get_errors(self, form, **kw):
    if not kw:
        return {'xxx':'unsubmitted form.'}, kw
    @validate(form=form)
    def valid(self, tg_errors=None, **kw):
        return tg_errors, kw
    return valid(self, **kw)

The problem has to do with the separate validator on 'id'. When the
@tg.validate line is commented out, the form is validated as expected
by get_errors. However when 'id' is validated, the form is not. This
doesn't seem to make sense; 'id' is not a field of the form so the two
validations should be independent, but apparently they're not. Any
hints ?

George


On Mar 27, 8:54 pm, "Ian Wilson" <[EMAIL PROTECTED]> wrote:
> First usually form fields are set when you instantiate the form.  Like this
> querySetForm = ListForm(
>    fields = [
>        TextField(name="foo",
> validator=validators.String(not_empty=True, max=16)),
>        FieldSet(fields=[
>            TextField(name="bar",
>                          validator=validators.String(not_empty=True,
> max=16))])
>
> Also I think the validator is not getting attached properly because
> the field set needs a name.  This should probably cause some sort of
> error so maybe that is a bug.
>
> So overall your example should look something like this:
> querySetForm = ListForm(
>    fields = [
>        TextField(name="foo",
> validator=validators.String(not_empty=True, max=16)),
>        FieldSet(name = "barwrapper", fields=[
>            TextField(name="bar",
>                          validator=validators.String(not_empty=True,
> max=16))])
>
> To take it even further I've found that using widgets.WidgetsList and
> validators.Schema make my forms easier to use and debug.  So ,although
> slightly overkill and wordy, this is the fanciest way to do it:
>
> #Schemas
> class BarWrapperSchema(Schema):
>     bar = String(not_empty=True, max=16)
>
> class QuerySetSchema(Schema):
>     foo = String(not_empty=True, max=16)
>     barwrapper = BarWrapperSchema()
>
> #Widgets
> class BarWrapperFields(WidgetsList):
>     bar = TextField()
>
> class QuerySetFields(WidgetsList):
>     foo = TextField()
>     barwrapper = FieldSet(fields = BarWrapperFields())
>
> #Form
> querySetForm = ListForm(fields=QuerySetFields(), validator=QuerySetSchema())
>
> Tell me if this doesn't make sense or still isn't working for you.
>
> -Ian
>
> On 3/26/07, George Sakkis <[EMAIL PROTECTED]> wrote:
>
>
>
> > On Mar 23, 2:24 am, "Ian Wilson" <[EMAIL PROTECTED]> wrote:
>
> > > The short answer is you don't really need anything special but its
> > > hard to tell from the details provided.  Can you give your form
> > > declaration ? And your correspondingvalidation.. or I guess that
> > > would be in the form declaration in your case.
>
> > > -Ian
>
> > > On 3/22/07, George Sakkis <[EMAIL PROTECTED]> wrote:
>
> > > > I'm trying to set up a form with a fieldset that has a bunch of
> > > > widgets. The generated html uses dotted names for the inputs such as
> > > > name="widget.description" etc. Now when I submit the form and just
> > > > return the **kwds without a template, I get anesteddict like
> > > > {"widget": {"description": "", "name": "", "queries": ""}}
>
> > > > The thing is that some of thenestedfields have validators but they
> > > > don't seem to apply. If I don't use the fieldset and attach the fields
> > > > directly to the form,validationworks fine. Is there anything special
> > > > I should do to activatevalidationonnestedwidgets ?
>
> > > > George
>
> > Here's a minimal example:
>
> > class QuerySetForm(ListForm):
> >     fields = [
> >         TextField(name="foo",
> > validator=validators.String(not_empty=True, max=16)),
> >         FieldSet(fields=[
> >             TextField(name="bar",
> >                           validator=validators.String(not_empty=True,
> > max=16))]),
> >     ]
>
> > The generated html has "requiredfield" class only for the "foo"
> > widget, not "bar". Is this a bug or what ?
>
> > George


--~--~---------~--~----~------------~-------~--~----~
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?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to