vendredi 24 juillet 2015

Rails hidden form not showing when checkbox is checked

I have several pages in a rails application that has a checkbox that shows/hides a form input. 2 out of the 4 places are functioning correctly, but the other two aren't. Maybe you guys can find what I'm missing.

Here's the view from a functioning page ...

<div class='span11' style="padding:1em; border-left:1px solid #ddd; border-right: 1px solid #ddd; width:910px;">
<%= render partial:'shared/external_requestor_toggle', locals:{nest:'rx_search_request'} %>
      </div>

Now here's one of the non-functioning views ...

<%= render partial:'shared/external_requestor_toggle', locals:{nest: 'insight_report'} %>
<%= submit_tag "Run Dispenser Activity Report", :class => 'btn' %>

And here's the other non-functioning view ...

<%= render partial:'shared/external_requestor_toggle', locals:{nest: 'insight_report'} %>
<%= submit_tag "Run Prescriber Activity", class:'btn' %>

Now, all three of those snippets call the file external_requestor_toggle which is here ...

<% if current_user.is_admin? %>
<% enable_hide = local_assigns["visible"].nil? %>
<% if local_assigns[:nest].nil? %>
  <% hash_format = 'external_requestor_attributes[%s]' %>
<% else %>
  <% hash_format = "#{nest}[external_requestor_attributes[%s]]" %>
<% end %>

<div id="external_requestor" style="">
  <label for='external_requestor_enable' class='checkbox'>
  <%= check_box_tag 'external_requestor_enable', 'enabled', false, {"data-toggle" => "#{enable_hide ? 'collapse' : ''}", "data-target" => "#external_requestor_options"} %> Run on behalf of...
  </label>

  <div class=" <%= enable_hide ? 'collapse' : '' %>" id="external_requestor_options" style='margin-top:1em;'>
    <div class="controls required">
      <label class="control-label" for="<%=hash_format % 'first_name'%>">First Name</label>
      <%= text_field_tag (hash_format % 'first_name'), "" %>
    </div>


    <div class="controls required">
      <label class="control-label" for="<%=hash_format % 'last_name'%>">Last Name</label>
      <%= text_field_tag (hash_format % 'last_name'), "" %>
    </div>

    <div class="controls">
      <label class="control-label" for="<%=hash_format % 'role_id'%>">As Role</label>
      <%= select_tag (hash_format % 'role_id'), options_from_collection_for_select(Role.ordered, "id", "name") %>
    </div>

    <div class="controls">
      <label class="control-label" for="<%=hash_format % 'annotation'%>">Annotation</label>
      <%= text_area_tag (hash_format % 'annotation'), "" %>
    </div>
  </div>
</div>
<% end %>

What's even more weird, from debugging the above file, I found that variables enable_hide is true for all 3 scenarios and local_assign[:nest].nil? is false for all 3 cases. hash_format might be where the problem is?

Any ideas?

Aucun commentaire:

Enregistrer un commentaire