On Tue, May 5, 2009 at 9:53 PM, Christoph Zwerschke <[email protected]> wrote: > > Sanjiv Singh schrieb: >> No. I think it would have to be handled by the calling javascript >> code. Although I dont find any onfailure or a similar property in the >> api here http://malsup.com/jquery/form/#api :( >> Any idea on what would be the best way to handle errors here? > > I looked into this some more. If you set "target", then in fact you have > no way to make a case distinction for errors, the result is always put > into the target element. But if instead of "target", you can set > "dataType" to e.g. "json" and "success" to a js_callback function, .e.g > > my_ajax_form = ActiveForm(id="myAjaxForm", > action="do_search", fields=CommentFields(), > dataType = 'json', success = js_callback( > "function (data) $('#' + data.target).html(data.output)")) > > Now you could implement the controller like this: > > @expose('json') > @validate(my_ajax_form) > def do_search(self, **kw): > if tmpl_context.form_errors: > target = 'my_ajax_form' > output = re.sub('<form [^>]*>|</form>', '', > Markup(my_ajax_form(kw))) > else: > target = 'output' > output = '<p>Received data: %s</p>' % kw > return dict(target=target,output=output)
This is really cool :) Thanks a lot Chris. > > In case of a validation error, this will redisplay the form with the > error messages, otherwise show the result. > > I also noticed that besides tw.jquery.AjaxForm, there is a > twAjaxTools.AjaxTableForm widget which seems to include some support for > validation as well as flash and redirect. Maybe we should add > documentation for that as well? Strangely, the ajax_form.js file from > that package is also in tw.jquery. I wonder how it got there because it > has nothing to with jquery and is not used by tw.jquery at all? True, we are using jquery.form.js here. regards Sanjiv > > -- Christoph > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "TurboGears Trunk" 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-trunk?hl=en -~----------~----~----~----~------~----~------~--~---
