Toggling functions in matrix.js


I’ve been working on a solution to the fact that toggling visibility with toggle_element() doesn’t persist when you save & stay or switch between pages. Joshua’s solution on the sentential negation subpage seems to work pretty well – essentially, he adds a call to some javascript to the header of the subpage that loops through the radio buttons of the question that controls toggling, and, if a choice is selected, makes sure the correct section is visible. This works well on my subpage as well, but seems to break down as soon as I try putting the radio button question inside an iterator. The problem seems to be that, although I’m looping over all the radio buttons, they all register as unchecked. As soon as you move the question outside the iterator, the issue disappears, and checked buttons register as checked again. Does anyone have any idea of why this would happen?


The issue seems to be that choices inside the iterator are prefixed with iterator-name1, where 1 is the number of the iterator. That number 1 is represented as something like {i} within matrixdef, but by the time you get to matrix.js, a real number needs to have been substituted in. Fixing that meant that I was able to access the properties of the radio button, including the checked property, which was the missing piece.