Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #8771: observe_field_examples.diff

File observe_field_examples.diff, 2.4 kB (added by andrej, 1 year ago)
  • actionpack/lib/action_view/helpers/prototype_helper.rb

    old new  
    269269      # Required +options+ are either of: 
    270270      # <tt>:url</tt>::       +url_for+-style options for the action to call 
    271271      #                       when the field has changed. 
     272      # 
     273      #                       Example 
     274      # 
     275      #                       :url => {:controller => 'graph', :action => 'new'} 
    272276      # <tt>:function</tt>::  Instead of making a remote call to a URL, you 
    273277      #                       can specify a function to be called instead. 
    274278      #  
     
    293297      #                         :with => "'my_custom_key=' + value" 
    294298      #                         :with => "'person[name]=' + prompt('New name')" 
    295299      #                         :with => "Form.Element.serialize('other-field')" 
     300      #                         :with => "'id=' + escape(value)" 
    296301      # 
    297302      #                       Finally 
    298303      #                         :with => 'name' 
     
    307312      # 
    308313      # Additionally, you may specify any of the options documented in 
    309314      # link_to_remote. 
     315      #  
     316      # A typical application updates a <div id='graph'> with the result of an AJAX  
     317      # call and also shows a spinner in <div id='spinner'> while loading. 
     318      # 
     319      # Example: 
     320      #   <%= observe_field('id',  
     321        #                 :update => "graph",  
     322        #                 :url => {:controller => 'graph', :action => 'new'},  
     323        #                 :with => "'id=' + escape(value)", 
     324        #                 :loading => "Element.hide(\"graph\");Element.show(\"spinner\");", 
     325        #                 :complete => "Element.hide(\"spinner\");Element.show(\"graph\");") %> 
     326        # 
     327        # or alternatively use the <tt>Element.toggle()</tt> javascript 
     328        # 
     329      #   <%= observe_field('id',  
     330        #                 :update => "graph",  
     331        #                 :url => {:controller => 'graph', :action => 'new'},  
     332        #                 :with => "'id=' + escape(value)", 
     333        #                 :loading => "Element.toggle(\"graph\");Element.toggle(\"spinner\");", 
     334        #                 :complete => "Element.toggle(\"spinner\");Element.toggle(\"graph\");") %>                                                
    310335      def observe_field(field_id, options = {}) 
    311336        if options[:frequency] && options[:frequency] > 0 
    312337          build_observer('Form.Element.Observer', field_id, options)