Observers Don't Save State Across Form Submit [Help]

Hello, any help with the issue below would be much appreciated!

I have a from that I use the observe_field method on to “watch” a drop
down box. Depending upon how the drop down box changes, I update the
contents of a div with more form fields for the user to fill out. A
small example, you can imagine a drop down box for the “Make” of a
car. When the user selects “Honda” from this drop down box, the
observer would update the contents of a div with another drop down box
that asks for “Model” (so the user could choose “Civic” or something).

This works well when the user submits the form and it validates and
saves, but when the form contains errors and doesn’t validate, only
the state of the drop down box is saved. The additional form fields
that are triggered by that drop down are not displayed.

To get it to show up, the user has to change the value of the drop
down to something other than what it is, and then change it back.
This is not what should be happening here.

Here is some code to try and make this more clear:

On the “new.html.erb” page I have this code:

<%= collection_select :app_session_parameter_group, :attack_type,

[“Select…”].concat(AppSessionParameterGroup.attack_types), :to_s,
:to_s
%>

<%= observe_field :app_session_parameter_group_attack_type,
:url => { :action => :attack_type_callback },
:update => :attack_type_div,
:with =>
“‘app_session_parameter_group[attack_type]=’+encodeURIComponent(value)”
%>

 

When the user changes the “attack_type” drop down box to “reboot”, the
“attack_type_div” gets filled in with this:

<%= text_field_tag ‘app_session_parameter_group[probability]’,
‘’, :size => 4 %>

The user should then see this new div, and specify a value for
probability. If they type in an invalid probability, like anything
less than zero or greater than one, when they submit the page it fails
to validate.

The problem is that when the page fails to validate, the drop down
still says “reboot” but the “probability” form field isn’t there! To
get it to show up, the user has to change the “attack_type” to
something other than “reboot” and then change it back.

Is there a way to fix this behavior so that when the page reloads the
drop down box will still be there with the red error frame around it?