Pick, group, and rank custom validation | XM Community
Skip to main content
Question

Pick, group, and rank custom validation

  • June 28, 2023
  • 3 replies
  • 282 views

Forum|alt.badge.img+2

I am setting up a research survey where I utilize the pick, group, and rank question type to ask respondents to sort a list of 18 statements into 4 different boxes. Up to 6 statements can be placed in each category, so it is possible that all statements could be sorted into 3 boxes and 1 category will remain empty. However, I need to verify that all 18 statements have been sorted. Currently I have validation set up so that each box can contain a minimum of 0 statements and a maximum of 6 statements, but this does not ensure that all statements were sorted into a box. 

Is there a custom validation method that I could use to ensure that the respondent sorts all 18 statements before proceeding?

3 replies

TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 6084 replies
  • June 28, 2023

Turning on Force Response will ensure that all statements are placed in a group.


Forum|alt.badge.img+2
  • Author
  • 1 reply
  • July 11, 2023

@TomG  Both Force Response and custom validation (each box can contain a minimum of 0 statements and a maximum of 6 statements) are both turned on, however, when I preview the survey I am allowed to place 1 statement in each box and move on, leaving 14 statements unsorted.


Tom_1842
Level 8 ●●●●●●●●
Forum|alt.badge.img+28
  • Level 8 ●●●●●●●●
  • 909 replies
  • July 20, 2023

Hi, if you turn off the Validation and just use Force Response, the respondent will need to sort all 18 statements before moving on. To keep the condition that each group must contain between 0 and 6 items, I was able to adapt the code of qualtrics_nerd in this post to add JavaScript to the PGR question that will disable the Next button after 200 milliseconds if any group contains more than 6 items. I added that delay so the next button would enable when removing a 7th item from a group to make it 6 and pass the condition.

So first, enable "Force Response" so that all statements will get placed, disable "Add validation", and then add the below to the OnReady section of the question's JavaScript:

//to access the question body to apply event listener
let ques=document.getElementById("Questions");

//to access the groups in which options are dragged
let quest=document.querySelectorAll("[role=list]");

//to access the next button
let button=document.getElementById('NextButton');

//function to check items in groups
function check() {
setTimeout(function() {
for(let i=1;i<quest.length;i++)
{
//validates the condition
if(quest[i].childElementCount>6)
{
button.disabled=true;
break;
}
else
{
button.disabled=false;
//enables the button and breaks from the loop if condition is not satisfied
}
}
}, 200);
}

//event listener on question body for when mouse is released
ques.addEventListener("mouseup", function(event) {
check();
});

//event listener on question body for when touch is ended
ques.addEventListener("touchend", function(event) {
check();
});