I have a dynamic list in a repeat region showing questions. By clicking the button (later image) I want to toggle the answer. I followed instructions form https://community.wappler.io/t/toggle-any-element-visibility/3882. But no joy.
Well how do you target the proper answer when it is in a repeat region? Have you applied dynamic IDs to your answers?
This code won’t work like that in your case. It’s suitable for single element toggle, not like in your case in a repeat region.
I noticed that it won’t work in my case. How can I get it to work in my case? Sorry for being a nuisance
Well, just change the logic to use a dynamic value instead of static.
<button class="btn" dmx-on:click="toggler.setValue($index)">Button</button>
<div dmx-show="toggler.value == $index" dmx-html="antwoord"></div>
And leave the initial value of the variable empty, instead of ‘0’
Jut for your info - the
$index expression in a repeater returns the index of the element, starting from 0.
That worked. I noticed I can open, but can not close. Is that correct?
If you want to toggle visibility change the onclick event value to:
dmx-on:click="toggler.setValue((toggler.value == -1 || toggler.value != $index) ? $index : -1)"
and set the initial value of the toggler variable to:
Last question on this subject (I hope). Is it possible to have multiple different togglers from say four different query’s on one page? Now it opens as for index same lines for all four at the same time.
The way you currently built your page you can use 4 different variables for each of your repeat regions.
Ok, I just added nn+$index where nn represents 100, 200, 300 and 400 for each repeat region. It seems to work.
That’s also a nice solution
Working like a charm now. Have a good weekend!