Technical
RJS

To disable Element using RJS


#html
<input id="Sec2Override_nvalue" name="Sec2Override[nvalue]" size="30" type="text" />
#RJS
render :update  do |page|
   page["Sec2Override_nvalue"].disabled = true
end 
#or 
render :update do |page|
  page.element.disable('element_name')
end

To disable form on load or complete


<%= form_tag {:action => ""},{:id => "search_form"} %>
<%= text_field_with_auto_complete :search,
                                  :q,
                                  {
                      :loading =>'Form.disable("search_form")',
                      :complete => 'Form.enable("search_form")'
                      }
<%= end_form_tag %>

To redirect when call was made by form_remote_tag


render :update do |page|
  page.redirect_to :controller => "legal_entity" 
end  

form_remote_tag with disable on loading and enable on complete
This should be refactored IMHO, because it can get very harry.


  <%= form_remote_tag(:url => {:action => "search_borrow_list"},
                                :loading => 'Form.disable("search_form")',
                                :complete => 'Form.enable("search_form")',
                          :html => {
                                :id => "search_form",
                                :style => "margin:0px 0px 0px 0px" 
                              }
                         ) %>

link_to_remote – with id and other html parameters

Yes, it confuses me every time I need to use it out of ordinary, and unfortunately Rail’s Docs are really skimpy on this one.


     <%= link_to_remote("&darr;",
         {
          :url => {   
            :action => "show_ordered_averages",
            :order => "bg_location_id",
            :lmp_type_select => params[:lmp_type_select]
          }, #=> url params
          :with => "'bg_location_id_sort_dir='+$('bg_location_id_sort_dir').value",
          :loading => "Element.show('average-title-indicator')",
          :complete => "Element.hide('average-title-indicator')" 
        },
          {:id => "bg_location_id_link"} #=> html params go here
        ) %>

Inserting raw ajax in to the page object


 page << "$('start_stop_flag_div').style.color='red'" 

In this particular case I change the color of the text in the start_stop_flag_div to red

How to call custom javascript function from your RJS code

Some times you would want to call js function from your RJS code using your page object ( or however else you called it ). You can do it the following way:


  page.call "play_sound","alert" 

Where play_sound is js function and alert is one of the parameters.
For more on the RJS and many other stuff follow this