Have an idea?

Visit Sawtooth Software Feedback to share your ideas on how we can improve our products.

Subheaders within a mutli-select question

Say I want to select which football teams I like to root for and I use the select question. The typical layout would look this this:

--Kansas City
--San Diego
--New Orleans
--Tampa Bay

However, I want to have sub-headers to give it a slight "hierarchy" look:

AFC West
--Kansas City
--San Diego

NFC South
--New Orleans
--Tampa Bay

How can I make this happen in the preformatted select question type. Doing free format works, but if I can mitigate user error is setting up the numeric equivalents, I'd like to explore that.

Preemptive thanks to Zachary and/or Paul Moon as I am sure they'll be the first to respond :)
asked Apr 11, 2016 by Colin Linerode Bronze (1,625 points)
I would have supplied a similar solution Justin Luster provided me with a few years ago. This solution, along with Zachary's both work beautifully.

1 Answer

+2 votes
Ha ha.  Looks like I've got Paul beat today.

I would do this with jQuery's 'before' or 'after' functions, like so:

<script type="text/javascript">
    $('#SelectQ_div > .question_body .response_column > div:nth-child(1)')
        .before('<div>AFC West</div>');
    $('#SelectQ_div > .question_body .response_column > div:nth-child(6)')
        .before('<br><div>NFC South</div>');

You can change the "nth-child" value to modify where to place the text in the list.
answered Apr 11, 2016 by Zachary Platinum Sawtooth Software, Inc. (205,975 points)
What are your constructed list instructions?  Are you observing that your groups of items are appearing in randomized order in your final constructed list?
My constructed list instructions are:

List 1:
ADD (Q18MasterList,1,3)

List 2:
ADD (Q18MasterList,4,6)

List 3:
ADD (Q18MasterList,7,12)

List 4:
ADD (Q18MasterList,13,17)

List 5:
ADD (Q18MasterList,18,20)

List 6:
ADD (Q18MasterList,21,23)

Final List that I am using in the question:


I am observing the items in each group (List) are randomized but not the groups.  They appear in the order of Q18List
"Subheaders" doesn't rearrange items.  It just adds the headers.  Your final constructed list always combines the other constructed lists in the same order, resulting in the behavior you're observing.

Try setting your final constructed list to use these instructions:

Begin Unverified Perl
# Parameters
my @lists = ('list1', 'list2', 'list3');

# Run
my $i = scalar @lists;
while ($i--) {
    my $j = int(rand($i + 1));
    @lists[$i, $j] = @lists[$j, $i];

foreach my $list (@lists) {
End Unverified

Line 3 must be updated with the number of and names of the other constructed lists.

The "subheader" labels are not appearing now.   I tried to take a shot by adding the code:

my @labels = ('Aske for Assitance/Advice', 'Look at Prices/Promotions', 'Find/Buy Product by Brand', 'Look for Information', 'Use my Mobile Device' , 'Other' );

But this didn't work
I did find my error.   The code you provided is PERFECT THANK YOU so much for all of your help you SAVED me a LOT of work  because I was going to add the list in different orders