On Wednesday, July 28, 2010 17:39:09 Seaky wrote:
> Hi,
>
> I am currently set up a ajax form (code below)
> But I don't manage the error return.
>
> I would like a result like, but in Ajax :
> http://www.turbogears.org/2.0/docs/_images/movie_form_6.png
>
> Please, help me..
>
> class CommentFields(WidgetsList):
> """The WidgetsList defines the fields of the form."""
>
> name = TextField(validator=validators.NotEmpty())
> email = TextField(validator=validators.Email(not_empty=True),
> attrs={'size':30})
> comment = TextArea(validator=validators.NotEmpty())
> notify = CheckBox(label="Notify me")
>
> ajax_form = AjaxForm(id="ajax_form",
> fields=CommentFields(),
> target="output",
> action="do_search")
>
> class TestFormController(BaseController):
> """
> The project controller for the pimseotools application.
> """
> @expose('pimseotools.templates.testform')
> def entry(self, **kw):
> pylons.c.form=ajax_form
> return dict(value=kw)
>
> @expose()
> def api_validation_error(self, **kw):
> kw['errors'] = pylons.c.form_errors
>
> return dict(kw['errors'])
This is non-sensical, why do you stuff the errors into a dict if you then
simply return them?
Also, dict called with a dict just yields a copy of the dict... why don't you
just return the form_errors?
And what do you expect to happen with a dict returned without any argument to
expose? For JSON, you need to do
@expose("json")
...
>
> @expose()
> @validate(ajax_form, error_handler=api_validation_error)
> def do_search(self, **kw):
> return "<p>Recieved Data:<br/>%(name)s<br/>%(email)s<br/>%
> (comment)s<br/>%(notify)s<br/></p>" % kw
Both methods make no sense to me, as you seem to mix output types wildly. I
don't know anything about AjaxForm, but if it's in any way sane, it should
expect JSON-output.
If not, where does AjaxForm come from?
Diez
--
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.