Christoph, First of all thank you for your excellent explanation and example this gives me a great place to start and try this example out. You are absolutely correct that it is on the server side that I am waiting for . So if I have any issue or questions I will let you know. Also I will let you know that it worked for me.
Thanks Again Rohan On Jan 18, 3:48 pm, Christoph Zwerschke <[email protected]> wrote: > Am 18.01.2010 14:28 schrieb hoboro: > > > I just want a response on the same page while the action is being > > processed. > > > Just display a message at the top "Processing Request Be Patient" > > thats it. when the action is done then move to the > > next page with the result. > > You still did not explain what you mean with "the action". So I assume > it's something done on the server side (done by a TG controller). > > If it is a relatively qick action, you should use a flash() call, as > explained by Diez (note that his code is for TG2, but it's similar for > TG1). This is the standard and simplest feedback method in TG. > > But I guess you're talking about an action that is somewhat slowish (say > 5 seconds) and you want to give the user a feedback that the submit > button has been clicked and the request is processed. > > Here is how you can do it using JavaScript with a simple widget in TG1. > > -------------------------------------------------------- > > from turbogears.widgets import mochikit, JSSource, Widget > > class WorkingWidget(Widget): > > template = """<h2 id="working" > style="border:1pt solid red;padding:6pt;width:12em;display:none"> > Working...</h2>""" > > javascript = [mochikit, JSSource(""" > addLoadEvent(function() { > connect(document.forms[0], 'onsubmit', function() { > appear('working'); > return true; > })});""")] > > working = WorkingWidget() > > --------------------------------------------------------- > > To check it out, add this to the controllers.py file of a quickstarted > project. We use the index page for both displaying the form and as the > form action target, but of course you can use different pages. > > In the template for the index page (welcome.kid in TG1.0, welcome.html > in TG1.1), you must show our widget and some form with a submit button: > > <div py:replace="working()"/> > > <form action="index" method="post"> > <p>Your name: <input type="text" name="name"/> > <input type="submit" name="ok"/></p> > </form> > > To simulate the slow action, let the controller sleep for 5 seconds. > Don't forget to pass our widget to the template. You can modify the > index method like this: > > �...@expose(template="foo.templates.welcome") > def index(self, **kw): > """"Show the welcome page.""" > if kw: > from time import sleep > sleep(5) > flash("Ok, I'm finished!") > return dict(working=working, now=datetime.datetime.now()) > > Of course, you can do more sophisticated stuff with AJAX. A simple way > of doing this is by making use of the RemoteForm widget. This will > normally give the feedback on the same page, but you can also add a > javascript redirect using the on_complete attribute. > > The basic usage is explained > here:http://docs.turbogears.org/1.0/RemoteFormWidgetTutorial > > Hope this helps, > -- Christoph
-- 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.

