Matrix custom validation force response for all but "Other" option | XM Community
Skip to main content

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();
}

 

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