Dynamic Accordion Usage

Here you are:

<div class="accordion" id="accordion1" is="dmx-repeat" dmx-bind:repeat="2">
 <div class="card">
  <div class="card-header" id="accordion_headingOne">
   <h5 class="mb-0">
   <button id="accordion1_collapseOne_Btn" class="btn btn-link" type="button" data-toggle="collapse" dmx-bind:data-target="#accordion1_collapseOne{{$index}}" aria-expanded="true" aria-controls="collapseOne">
   <i class="fal" dmx-class:fa-caret-right="accordion1.items[$index].this.collapsed" dmx-class:fa-caret-down="!accordion1.items[$index].this.collapsed"></i> Collapsible Group Item {{$index}}
    </button>
   </h5>
 </div>
<div dmx-bind:id="accordion1_collapseOne{{$index}}" class="collapse" is="dmx-bs4-collapse" aria-labelledby="accordion1_headingOne" data-parent="#accordion1" dmx-bind:show="($index == 0)" id="this">
  <div class="card-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.
   </div>
  </div>
 </div>
</div>

The important part is knowing that in a single accordion the collapsed boolean is stored in it’s own element:

accordion1_collapseOne.collapsed

While in repeating accordions you need to query the array element that belongs to the accordion.

accordion1.items[$index].this.collapsed

Then I just needed to switch classes depending on the state of the collapsable area.

<i class="fal" dmx-class:fa-caret-right="accordion1.items[$index].this.collapsed" dmx-class:fa-caret-down="!accordion1.items[$index].this.collapsed"></i>

No need to use CSS unless you want to do a fancy animation or other stuff.

Wappler Team It would be great to access the properties of a repeating collapse from UI.
So these bad guys -> dmx.app.data.accordion1.items

11 Likes