I am building a questionnaire tool where I use a loop layout to auto populate the question (and answer buttons). Currently, this is set up in a child module that is populating a parent module. I want to break these questions into their sections.
My object set to loop through has properties: questionnaireType, sectionName, QuestionText, IndexID. The loop filters based on questionnaireType selected to populate the QuestionText (sort by IndexID). I cannot see a way to group by in a simple loop layout - is this correct?
As a result, I am trying to do a loop in a loop where the “baby” module is the question loop as described above and then theres a child module above this that contains the section layout to loop through which finally populates the parent module. I am struggling with how to configure the middle layer to this so that the sections populate with the relevant questions. The parent module currently presents with each question in its own section loop.
The reason I am trying to approach it like this is because
a) the number of questions in a section differs section to section
b) the number of sections in a questionnaire differs as well
We’re currently tracking feature requests internally to be able to:
loop over an aggregation of an object set
loop over an array variable
In your case you could populate an array variable with a unique values aggregation of the questionnaireType or sectionName property, depending on what you want to group by. Then in the child module you could filter the original object set on the array property being looped over. With that in mind I believe either of these features would allow you to do what you want here.
Since these are not available yet, for now you can construct an object set (perhaps function backed) that contains one object with each value you want to display a section for, which leads to a similar solution as looping over an array variable.
Could you advise on rough steps that I would need to add to this to set up the looping desired? Happy playing around with getting it working but conscious I’m not clear on the specific steps to achieving the end goal.
We hope to have looping over an array out soon but no specific date right now, probably long enough out that it’s worth working around for now.
You’ll want your function to return an object set with one object with each property value you want to loop over. I don’t have a specific example to share but you’ll want to do something like groupBy the property you’re interested in, and then take the first object from each group. (perhaps something like a map of your grouped array to the first object in each group).