Matrix custom validation force response for all but "Other" option | XM Community
Question

Matrix custom validation force response for all but "Other" option

  • 22 April 2024
  • 1 reply
  • 18 views

Badge +1

I want to add forced response to a matrix question for all options other than “Other”. I’m able to achieve this through custom validation but applying this to every question is a strenuous task and also increase loading time.

 

Is there a way to use the following code that disables the next button until all but other option is selected. The selected count option won’t work because the respondent may choose the “Other” option and miss the compulsory option.

{
this.disableNextButton();
this.questionclick = function(event,element)
{
if (element.type == 'radio')
{
var numAnswered= this.getSelectedChoices()
if (numAnswered.length >= 3)
{
this.enableNextButton();
}
else
{
this.disableNextButton();
}

 


1 reply

Userlevel 4
Badge +12

Hi @mugheeshay you can exclude the selection of that particular choice in your javascript code.

Below is a code where the ‘Other’ option is at the 4th place. So the code is customized as follows - it will not increase the number counter if the selected choice has a digit ‘4’ in it. Similarly you can replace the digit 4 by the correct value at where your ‘Other’ option is situated. (I guess its 16, guessing from the image you provided).

   

Qualtrics.SurveyEngine.addOnload(function() {
    this.disableNextButton();
    this.questionclick = function(event, element) {
        if (element.type == 'radio') {
            var numAnswered = this.getSelectedChoices();
            // Exclude the specific choice from the count
            if (numAnswered.includes('4')) {
                numAnswered = numAnswered.filter(choice => choice !== '4');
            }
            if (numAnswered.length >= 3) {
                this.enableNextButton();
            } else {
                this.disableNextButton();
            }
        }
    };
});
 

Leave a Reply