nathanvda / cocoon

Dynamic nested forms using jQuery made easy; works with formtastic, simple_form or default forms
http://github.com/nathanvda/cocoon
MIT License
3.09k stars 383 forks source link

Dynamic ids for things besides text fields #209

Closed AustinLMayes closed 10 years ago

AustinLMayes commented 10 years ago

NOTE This is not a gem issue, I'm just confused So I have a nested form

%h3
  Destroyables
  %small Teams can have multiple destroyables and they can be made out of multiple materials.
%panels
  = f.simple_fields_for :monuments do |monument|
    = render 'maps/parts/objectives/forms/monument_fields', :f => monument
    .links
      %br
      = link_to_add_association 'Add Destroyables', f, :monuments, :partial => 'maps/parts/objectives/forms/monument_fields', class: "btn btn-primary"

and in the form there is a collapsable panel

#accordion.panel-group
  #panel1.panel.panel-default
    .panel-heading
      %h4.panel-title
        %a{"data-target" => "#collapseOne", "data-toggle" => "collapse", href: "#collapseOne", :id => "panel-title"}
          Monument
    #collapseOne.panel-collapse.collapse.in
      .panel-body
        Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
      .panel-footer
        = link_to_remove_association "Remove Destroyable", f, class: "btn btn-danger"

The problem is, all of the models have the same id so collapsing is broken. I am at a loss on how to dynamically change those ids so they will each independently collapse. Any assistance is appreciated, Thanks

nathanvda commented 10 years ago

This is clearly not a gem issue, you do not even explain to me which collapse js you are using, soooooo a little hard for me to help.

Most of the times you can just use the class to activate whatever collapse js you are using.

Such questions which are completely not related to the gem, should be asked on stackoverflow.