Topic: Observe_form - Dynamically adding drop down box to form

I have managed to use observer_form to dynamically add a drop down box to a form based on the value of a particular field of the existing form.  The code looks like this right now:

- View

<%= start_form_tag ( { :action => 'scrub' }, 
                         :multipart => true, 
                         :id => 'importaction_form' ) %>
      <input type="hidden" name="MAX_FILE_SIZE" value="100000" />
        <b>File to scrub & load:    </b><%= file_field("upload", "data") %>
        <b>Timezone Processing type:  </b>
        <select name="timezone_processing">
          <option value="1">None</option>
          <option value="2">Timezone Table</option>
            <% if $webservice_lookup == true %>
                <option value="3">Webservice</option>
            <% end %>
        <b>Location to insert records:  </b>
        <select name="record_destination">
          <option value="1">Temporary Table</option>
          <option value="2">Presence Load</option>
        <div id="load_service_list">
    <%= submit_tag "Import CSV File" %>
    <%= end_form_tag %>
    <%= observe_form 'importaction_form',
                      :url => {:action => 'populateloadservice'},
                      :update => 'load_service_list',
                      :frequency => 5 %>

- Controller

def populateloadservice
    case params[:record_destination].to_s
      when "1"
        render :text => " "
      when "2"
        #render :text => "PCO..."
        render(:partial => "serviceloads", :layout => false)

This works, except for the fact that when someone attempts to access the new field added and select an option, it gets set back to defaults (ie - their selection disappears) every second as the form is being rendered again.

Any recommendations on how best to handle this?

Would it be to use the ':condtion' field as per?:

:condition:    Perform remote request conditionally by this expression. Use this to describe browser-side conditions when request should not be initiated. … ml#M000412

Last edited by muppetmaster (2006-11-13 07:46:51)