The input field 'self' was not expected.
Am I doing something wrong or is something broken? Code follows.
Cheers.
Jon.
@expose(template="cocoahaus.templates.user.error")
def error(self, tg_errors=None):
...
class FormFields(toscawidgets.api.WidgetsList):
user_name = toscawidgets.forms.TextField()
display_name = toscawidgets.forms.TextField()
email_address = toscawidgets.forms.TextField(validator =
validators.Email(not_empty=True))
create_form = toscawidgets.forms.TableForm(fields = FormFields,
submit_text = 'Save', name="", action="/user/save", method="post")
@expose(template="cocoahaus.templates.user.create")
def create(self):
...
return dict(form = create_form)
@expose()
@validate(form = create_form)
@error_handler(error)
def _save(self, user_name = None, display_name = None, email_address
= None):
...
> I'm using turbogears 1.0 (from svn branch @ r2202) and toscawidgets
> (latest from cheeseshop) to generate a form. Works fine until I turn
> on validation, as soon as I do my error handler gets triggered with
> the error message:
>
> The input field 'self' was not expected.
>
> Am I doing something wrong or is something broken? Code follows.
This is related to the way TurboGears does validation in the
@validate decorator as it introduces some unrelated variables in the
dict it passes to the Schema.
You can overcome this by defining the Schema like this:
from formencode.schema import Schema
class TGSchema(Schema):
filter_extra_fields = True
allow_extra_fields = True
and passing it as a validator to the form:
create_form = toscawidgets.forms.TableForm(fields = FormFields,
submit_text = 'Save', name="", action="/user/save", method="post",
validator=TGSchema)
The form will build it's schema from all fields' validators using
that schema. BTW, I this is more or less the way
turbogears.validators.Schema is defined for precisely the same reason...
Alberto
Thanks to your little trick now it finally works. But could there be a
friendlier way to make this work, or at least a warning or anything?
Especially beginners might really get in trouble the way it is now.
Besides that, using ToscaWidgets - especially after the recent fixes -
works pretty smooth and flawlessly, and the (just updated)
TinyMCE-widget is great. Thank you very much for your really great
work!
On 9 Dez. 2006, 17:14, Alberto Valverde <albe...@toscat.net> wrote:
> On Dec 9, 2006, at 4:05 PM, Jonathan Wight wrote:
>
> > I'm using turbogears 1.0 (from svn branch @ r2202) and toscawidgets
> > (latest from cheeseshop) to generate a form. Works fine until I turn
> > on validation, as soon as I do my error handler gets triggered with
> > the error message:
>
> > Theinputfield'self' wasnotexpected.
>
> > Am I doing something wrong or is something broken? Code follows.This is related to the way TurboGears does validation in the
>
> It took me quite some time today to figure that one out. I couldn't
> find this thread until now, because I didn't see the actual error
> message. My error page (that worked perfectly until switching to
> ToscaWidgets) just didn't show any errors at all, and I digged myself
> through pdb until I got the error message.
>
> Thanks to your little trick now it finally works. But could there be a
> friendlier way to make this work, or at least a warning or anything?
> Especially beginners might really get in trouble the way it is now.
Unfortunately not that I'm aware of... this is due to the way that TG
validates and is a TG-only related problem. I could make the Schema
twForms uses as a base to create containers' validators include those
attributes as default but it's a hack I don't want to impose on other
frameworks' users.
Maybe I should write a "Using ToscaWidgets with TG 1.0" document and
explain it clearly there.
>
> Besides that, using ToscaWidgets - especially after the recent fixes -
> works pretty smooth and flawlessly, and the (just updated)
> TinyMCE-widget is great. Thank you very much for your really great
> work!
Glad it works fine! :)
Thanks!
Alberto