I have a pannel which will have data in it for a form in rails
#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 panels are added dynamicly when the user clicks the "Add additional monument" button. My problem is, I need to change the value of the collapsable's id and so on to make each panel independently collapsable. I have absolutely no idea how to do this.
:javascript
$(document).ready(function() {
$('#accordion')
.on('cocoon:after-insert', function() {
var randValue=Math.random();
var element=document.getElementById("panel-title");
var panelement=document.getElementById("collapseOne");
element.setAttribute("data-target",randValue);
panelement.setAttribute("id",randValue);
});
That's probably really wrong, if you could help me make this work that would be great.The after-insert action is called after the panel is added to the page.
Also, is there a way to set the heading of the panel to an input's value?