Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Array (Numbers) - Checkbox - Mandatory response per column

More
7 hours 11 minutes ago - 7 hours 10 minutes ago #274235 by boshra.m
Please help us help you and fill where relevant:
LimeSurvey version: LimeSurvey Cloud Version 6.17.0
Own server or LimeSurvey Cloud: Cloud
Survey theme/template: Fruity 
==================
Hello,

I am trying to have an array (numbers) - checkbox question where it is mandatory that participants select at least one answer per column but I am not able to figure out how. I have tried using question validation but I am unsuccessful. Would anybody know how to do this?

I have attached a .lss file.

I greatly appreciate it!

File Attachment:

File Name: limesurvey...1931.lss
File Size:41.83 KB

 
Last edit: 7 hours 10 minutes ago by boshra.m. Reason: Title name

Please Log in to join the conversation.

More
1 hour 56 minutes ago - 1 hour 55 minutes ago #274236 by Joffm
Hi,
please do not hard code the IDs of question, group or survey.
When you import the survey everything is broken.
Use {QID}, {GID}, {SID} instead.

And I wonder why you didn't use the often shown solutions to
1. add an "Other"-option to an array
Code:
<script type="text/javascript" charset="utf-8">    
    $(document).ready(function() {
 
        // Identify the questions
        var thisQuestion = $('#question'+{QID}+'');
        var nextQuestion1 = $(thisQuestion).nextAll('.text-short:eq(0)');
        var nextQuestions = $(nextQuestion1);
        var nextLength = nextQuestions.length;
        var sqLength = ('tr.answers-list', thisQuestion).length;
 
        // Hide the short-text questions
        $(nextQuestions).hide();
 
        // Move the hidden text inputs into the array
        for (i = 0; i < nextLength; i++) {
            var workingIndex = (sqLength - 1) - (nextLength - i);
            var nextQ = nextQuestions[i];
            $('th.answertext:eq('+workingIndex+')', thisQuestion).append($('input[type="text"]', nextQ)).closest('tr').addClass('otherRow');
        }    
 
        // Some styling...
        $('input[type="text"]', thisQuestion).css({
            'width': '100%'
        });
    });
</script>[/i]


2. to make a row exclusive.
Something you yourself asked for 3 and a half years ago.
[url] forums.limesurvey.org/forum/installation...king-a-row-exclusive [/url]
Code:
<script type="text/javascript" data-author="Tony Partner">
 
  $(document).on('ready pjax:scriptcomplete',function(){
 
    // Identify this question
    var thisQuestion = $('#question{QID}');
 
    // Identify the exclusive row
    var thisTable = $('table.subquestion-list', thisQuestion);
    var exclusiveRow = $('tr[id^="javatbd"]:last', thisTable);
    $(exclusiveRow).addClass('exclusive-row');
 
    // Listener on the checkboxes
    $(':checkbox', thisTable).on('change', function(event){
      if($(this).is(':checked')) {
        var thisRow = $(this).closest('tr');
 
        // Identify the column
        var thisIndex = $(this).closest('td').index();
 
        // Identify the radios to be un-checked
        var excludedItems = $('tr.exclusive-row td.answer-item:nth-child('+(thisIndex+1)+')', thisTable);
        if($(thisRow).hasClass('exclusive-row')) {
          excludedItems = $('tr:not(.exclusive-row) td:nth-child('+(thisIndex+1)+')', thisTable);
        }
 
        // Un-check those checkboxes
        $.each(excludedItems, function(i, thisItem) {
          $('input[type="hidden"]', thisItem).val('');
          $(':checkbox', thisItem).prop('checked', false).trigger('change');
        });
      }
    });
  });
</script>

You only have to change the "last" to the row where your students are. And you may add the disabled property.
Though in my opinion this is annoying. The respondent has to click twice to remove the selection of "all" and select another item.

Well, now to your question
question validation equation (X1, X2,... are the x-axis codes)
sum(count(self.sq_X1)>0,count(self.sq_X2)>0,count(self.sq_X3)>0,count(self.sq_X4)>0)==4




 

File Attachment:

File Name: limesurvey...1931.lss
File Size:41.05 KB


Joffm


 

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 1 hour 55 minutes ago by Joffm.

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose