Have an idea?

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

How to use free format to build a constructed list

Hi,

I have a long list with 4 groups of a total of 20 items, and I would like people to choose a total of 8 items out of the 20 items, with the requirement that you must choose at least two from the same group (you can choose none).  Any idea how to best achieve this?

My thought is to use a free format question to build a constructed list out of the long list.  However I don't know 1) how to write the data validation 2) how to transfer the free format variable to a constructed list.  I would appreciate any help!
asked Aug 5, 2013 by anonymous

2 Answers

0 votes
I'm not sure if I see the need for a free format unless you wanted a very special layout.  You could achieve this with a normal select question and then write some custom JavaScript validation.  See the Custom Validation section at https://www.sawtoothsoftware.com/support/issues/ssiweb/online_help/index.html?hid_web_advanced_javascript.htm.
answered Aug 5, 2013 by Brian McEwan Gold Sawtooth Software, Inc. (39,270 points)
0 votes
I can answer the look of the question now and will have a go at the verification tomorrow morning.

Create a parent list called ItemList which should look like this ...

1 Item 1
2 Item 2
...
...
19 Item 19
20 Item 20
21 <span class="group_header"><b>Group 1</b></span>
22 <span class="group_header"><b>Group 2</b></span>
23 <span class="group_header"><b>Group 3</b></span>
24 <span class="group_header"><b>Group 4</b></span>
25 <span class="group_header"><b>Group 5</b></span>

Create a constructed list called ItemConList ...

ADD(ItemList,21)
ADD(ItemList,1,4)
ADD(ItemList,22)
ADD(ItemList,5,8)
ADD(ItemList,23)
ADD(ItemList,9,12)
ADD(ItemList,24)
ADD(ItemList,13,16)
ADD(ItemList,25)
ADD(ItemList,17,20)

Use the constructed list ItemConList in your question.

In the survey settings under the headers and footer tab, copy the following script into the HTML head tag ...

<script src="[%GraphicsPath()%]jquery-1.6.2.min.js"></script>

<script type="text/javascript">
  $.noConflict();

jQuery(document).ready(function(){

  jQuery(".group_header").parents("tr.clickable").each(function(index) {
    var HeaderRowObj = jQuery(this);
   
    HeaderRowObj.removeClass("clickable");
    HeaderRowObj.addClass("group_header_row");

    var InputObj = HeaderRowObj.find("input");
    InputObj.addClass("HideElement");  //Make sure it is hidden

    var GroupHeaderObj = HeaderRowObj.find(".group_header");

    HeaderRowObj.html("<td colspan='2'>" + GroupHeaderObj.html() + "</td>");
    HeaderRowObj.prepend(InputObj);

  });
});

</script>


Copy the file jquery-1.6.2.min.js into your graphics folder of your survey. Let me know if you need this file. I can send it if you do not have it already.
 
This question will now have a nice look with each group of codes having a sub-group heading in bold.

I'll try to get back to you tomorrow with some verification JavaScript. I'm hoping I can work that out.
answered Aug 6, 2013 by Paul Moon Platinum (74,405 points)
Wow, this is great.  I'll try this out and let you know if this works.  Thanks so much!
This works. I have tried it out. Thought I should mention this was tested on v7 but moving to v8 soon.
Attached is the JavaScript code that verifies if more than 2 items have been selected from any of groups 1-5. Assume your question is QP.

This could be made more efficient with some "for loop" programming but this does the job nicely.

var count1=0
var count2=0
var count3=0
var count4=0
var count5=0

if(document.mainform["QP_1"])
 {
  if(document.mainform["QP_1"].checked)
     {
      count1=count1+1
     }
      
  if(document.mainform["QP_2"].checked)
     {
      count1=count1+1
     }

  if(document.mainform["QP_3"].checked)
     {
      count1=count1+1
     }

  if(document.mainform["QP_4"].checked)
     {
      count1=count1+1
     }

  if(document.mainform["QP_5"].checked)
     {
      count2=count2+1
     }
      
  if(document.mainform["QP_6"].checked)
     {
      count2=count2+1
     }

  if(document.mainform["QP_7"].checked)
     {
      count2=count2+1
     }

  if(document.mainform["QP_8"].checked)
     {
      count2=count2+1
     }

  if(document.mainform["QP_9"].checked)
     {
      count3=count3+1
     }
      
  if(document.mainform["QP_10"].checked)
     {
      count3=count3+1
     }

  if(document.mainform["QP_11"].checked)
     {
      count3=count3+1
     }

  if(document.mainform["QP_12"].checked)
     {
      count3=count3+1
     }
  if(document.mainform["QP_13"].checked)
     {
      count4=count4+1
     }
      
  if(document.mainform["QP_14"].checked)
     {
      count4=count4+1
     }

  if(document.mainform["QP_15"].checked)
     {
      count4=count4+1
     }

  if(document.mainform["QP_16"].checked)
     {
      count4=count4+1
     }
  if(document.mainform["QP_17"].checked)
     {
      count5=count5+1
     }
      
  if(document.mainform["QP_18"].checked)
     {
      count5=count5+1
     }

  if(document.mainform["QP_19"].checked)
     {
      count5=count5+1
     }

  if(document.mainform["QP_20"].checked)
     {
      count5=count5+1
     }
 }

if (count1>2 || count2>2 || count3>2 || count4>2 || count5>2)
 {
  if (count1>2)
    {
     strErrorMessage="You have made too many selections within Group 1. Please review your answers before continuing.";
    }
  if (count2>2)
    {
     strErrorMessage="You have made too many selections within Group 2. Please review your answers before continuing.";
    }
  if (count3>2)
    {
     strErrorMessage="You have made too many selections within Group 3. Please review your answers before continuing.";
    }
  if (count4>2)
    {
     strErrorMessage="You have made too many selections within Group 4. Please review your answers before continuing.";
    }
  if (count5>2)
    {
     strErrorMessage="You have made too many selections within Group 5. Please review your answers before continuing.";
    }
 }
else
 {
  strErrorMessage="";
 }

Paul, could you please email me jquery-1.6.2.min.js to honghu2012@gmail.com?  Thought I'd look for it myself but wanted to make sure I get the right version ...  Thanks so much!
The file has been sent.
...