Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Changes between Version 3 and Version 4 of RemoteForm

09/20/06 22:29:27 (13 years ago)

It's not much, and it's broken, but it's better than "ghjghjgjfgjgh"!


  • RemoteForm

    v3 v4  
    1 ghjghjgjfgjgh 
     1=== WARNING === 
     2This example doesn't actually work for me.  For some reason, the RemoteForm is acting like a regular html form, serving up a new page instead of performing the replacements we're looking for.  I'll update this page as soon as I figure out why this is happening. 
     4== Overview == 
     6RemoteForm and it's companion widget, LinkRemoteFunction, provide an ajaxian method of presenting a form.  RemoteForm's purpose is to provide HTML's form functionality without forcing a page refresh.  
     9== Basic RemoteForm Usage == 
     10In this example, we're going to demo a form using TextField, CheckBox, and a Radio button. To start, in the controller, start by creating a class that contains the fields you want to display:  
     13from turbogears.widgets.base import WidgetsList 
     14from turbogears.widgets import TextField, CheckBox, RadioButtonList 
     15import turbogears as tg 
     17class SearchFormFields(WidgetsList): 
     18    name = TextField() 
     19    age = TextField() 
     20    check = CheckBox() 
     21    radio = RadioButtonList(options=[(1, "Python"), 
     22                                    (2, "Java"), 
     23                                    (3, "Pascal"), 
     24                                    (4, "Ruby")], 
     25                                    default=4) 
     29Then, expose a controller function to create the remote form upon request:  
     32class DemoController(identity.SecureResource): 
     33    """ Demonstrate the use of RemoteForm. """     
     34    @tg.expose(template="templates.remoteformdemo") 
     35    def index(self):         
     36        item_searchform = RemoteForm( 
     37            name="ItemSearch", 
     38            fields=SearchFormFields(), 
     39            submit_text="Search") 
     40        return dict(item_searchform=item_searchform) 
     43The last controller function is a call-back, which is used by the widget to retrieve the data inside it's asynchronous request. 
     46  @tg.expose(format = "json") 
     47  def do_search(self, **kw): 
     48      """ Echo the parameters back, json formatted. """ 
     49      return """Received data:<br />%r""" % kw 
     52Finally, in the template, call the widget's display function.  You can pass parameters to display() to customize the effects.  The example below displays "Searching..." during the XMLHttpRequest, and "Done!" when it completes.  
     55     <span py:replace="item_searchform.display( 
     56                                           action='/do_search', 
     57                                           target_dom='items', 
     58                                           before='getElement(\'loading\').innerHTML=\'Searching...\';', 
     59                                           on_complete='getElement(\'loading\').innerHTML=\'Done!\';', 
     60                                           confirm='Are you sure you want to submit this request?' 
     61                                           )"> 
     62    </span> 
     64    <div name="loading"></div> 
     65    <div name="items"></div> 
     69And that's it.   Browsers hitting our demo page will be served up some nice RemoteForm goodness. 
     73Note:  Most of the above was gleaned from the widget example in the toolbox.   See the demo there for a live example.