The following code works fine except for a single strange twist described below:
<%= form_for(:object) do |form| %>
<p id="batch_ops">
<b>Objects</b>
<%= submit_tag "Do This" %>
<%= submit_tag "Do That",
:confirm => "Really do that?" %>
<p id="capture" float="left">
<%= button_to_function "Operation_1", \
"Element.remove('batch_input_area'); Element.show('get_op1_params')" %>
<%= text_field_tag "op1_save_path", "op1_full_dir_path" %>
<%= button_to_function "Operation_2", \
"Element.remove('batch_input_area'); Element.show('get_op2_params')" %>
<%= text_field_tag "op2_save_path", "op2_full_dir_path" %>
</p>
<div id="batch_input_area" style="display:none;">
</div>
</p>
<ul id="object_list">
<% @objects.each do |c| %>
<li id="current_object" style="horizontal-align: left" width="auto"><b>
<%= hidden_field_tag('seen_objects[]', c.id) %>
<%= check_box_tag 'chkd_objects[]', c.id, c.object_checked? %>
<%= c.object_address %>
<% if c.data1? %>
<%= c.data1 %>
<% else %>
<%= "_____________" %>
<% end %>
<% end %>
</ul>
<div id="get_op1_params" style="display:none;">
<%= form_tag(
:action ="" 'index',
:remote => true,
:html => {:id => 'op1_form'}
) do %>
Options: <%= text_field :op1params, :op1_params, :value => 'freq=30 run=1 stop=0' %>
<%= submit_tag 'Op1 Run', :confirm => 'Run Operation_1 test on checked objects?' %>
<%= submit_tag 'Op1 Status' %>
<%= submit_tag 'Op1 Stop', :confirm => 'Stop Operation_1 test on checked objects?' %>
<%= link_to "Cancel", {:action ="" "index"} %>
<% end %>
</div>
<div id="get_op2_params" style="display:none;">
<%= form_tag(
:action ="" 'index',
:remote => true,
:html => {:id => 'op2_form'}
) do %>
Options: <%= text_field :op2params, :op2_params, :value => 'freq=30 run=1 stop=0' %>
<%= submit_tag 'Op2 Run', :confirm => 'Run Operation_2 test on checked objects?' %>
<%= submit_tag 'Op2 Status' %>
<%= submit_tag 'Op2 Stop', :confirm => 'Stop Operation_2 test on checked objects?' %>
<%= link_to "Cancel", {:action ="" "index"} %>
<% end %>
</div>
Now here's the twist: Over on the controller, the Operation_1 handler gets the checkbox presence array seen_objects[] and the activated elements of the checkbox state array chkd_objects[] while the Operation_2 handler does not. If I reverse the order of the get_op1_params and get_op2_params form_tag divs shown last above then the Operation_2 handler gets these checkbox arrays but the Operation_1 handler does not.
My question is simply: Why?
I've long since lost count of the different things I've tried to get around this, which included additional hidden_field_tags within the form_tags. Ultimately I gave up and used a far less elegant submit_tag with a text_field_tag in place of the Operation_2 button_to_function and its associated form_tag but still do not understand why I could not make both of these operations work using button_to_function as illustrated above.
The same description of this problem along with community feedback can be found at http://stackoverflow.com/questions/9643517/the-mysterious-order-dependent-checkbox-state-array-controller-transmission-anom.
|