Have an idea?

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

Skip logic for free format drag and drop question

Hello everyone,

I need your help concerning the skip logic for a free format drag and drop question.

What I actually need is a skip logic that does not let the participant skip the question if he does not drag at least one item from the left side (sortable1) to the right side (sortable3).
The drag and drop question is build up as follows:
On the left side, There is a List with 10 items. On the right side, there is a empty box where they have to drop in at least one item.

The following is my javascript:

var list = document.getElementById("sortable1");
     var items = list.getElementsByTagName("li");
     var itemsString = "";
     for (var i = 0; i < items.length; i++) {
          if (itemsString.length > 0) itemsString += ",";
         itemsString += items[i].innerHTML;
     var items2 = $('#sortable3 li');
     var itemsString2 = "";
     for (var i = 0; i < items2.length; i++) {
         if (itemsString2.length > 0) itemsString2 += ";";
         itemsString2 += items2[i].innerHTML;

  if(  $('#sortable1 li').length >= 10)
        strErrorMessage = "Bitte ziehen Sie Mindestens eine Ma├čnahme von links nach rechts.";   

/*Variablen-Anzahl hier anpassen */
document.getElementById('Q3Sparte_Rank1').value = items2[0].innerHTML;
document.getElementById('Q3Sparte_Rank2').value = items2[1].innerHTML;
document.getElementById('Q3Sparte_Rank3').value = items2[2].innerHTML;
document.getElementById('Q3Sparte_Rank4').value = items2[3].innerHTML;
document.getElementById('Q3Sparte_Rank5').value = items2[4].innerHTML;
document.getElementById('Q3Sparte_Rank6').value = items2[5].innerHTML;
document.getElementById('Q3Sparte_Rank7').value = items2[6].innerHTML;
document.getElementById('Q3Sparte_Rank8').value = items2[7].innerHTML;
document.getElementById('Q3Sparte_Rank9').value = items2[8].innerHTML;
document.getElementById('Q3Sparte_Rank10').value = items2[9].innerHTML;

What I have so far:
If I change ('#sortable3 li') to ('#sortable2 li') in the following, I get what I want but if I refer to my values, I do not get the chosen value (in text format) but I get the Number of ('#sortable2 li') which is my list from 1 to 10 which is on the left side of the open box to give the participant an rating orientation for the rating of chosen items.

This is the part where I would change ('#sortable3 li') to ('#sortable2 li'):
var items2 = $('#sortable3 li');
     var itemsString2 = "";
     for (var i = 0; i < items2.length; i++) {
         if (itemsString2.length > 0) itemsString2 += ";";
         itemsString2 += items2[i].innerHTML;

I hope you are not completely lost and can help me.

Thank you very much in advance,
asked Jan 25, 2017 by Tim
Tim, could you email a .ssi with your free format question to zachary@sawtoothsoftware.com?

1 Answer

0 votes
This custom JavaScript verification will require that at least one item be in the right bucket:

if ($('#sortable3 li').length === 0) {
    strErrorMessage = 'At least one item must be selected.';
answered Jan 26, 2017 by Zachary Platinum Sawtooth Software, Inc. (156,375 points)
Thank you very much for your help