Welcome to the LimeSurvey Community Forum

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

Making a row exclusive

  • boshra.m
  • boshra.m's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
1 year 5 months ago #233647 by boshra.m
Making a row exclusive was created by boshra.m
Please help us help you and fill where relevant:
Your LimeSurvey version: LimeSurvey Cloud Version 5.4.9
Own server or LimeSurvey hosting: LimeSurvey hosting
Survey theme/template: Fruity
==================
Hello,

I was wondering if it was possible to make a row exclusive in an array numbers, checkbox question? Specifically, is it possible that if a respondent selects the last row ("Not applicable (meal option not offered at your school)" in question 2.5), the rest of the column is blocked off or cleared out (similarly done for question 1.1)?

I was able to do something similar for columns where if they selected either None or Unsure, then they cannot select the first three columns (question 2.5).

Just wondering if this is possible. 

Thank you.

 

File Attachment:

File Name: Exclusive Test.lss
File Size:48 KB

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 5 months ago #233681 by tpartner
Replied by tpartner on topic Making a row exclusive
This little script placed in the question source of an array-numbers-checkboxes question will render the last row exclusive:

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>

Sample survey attached:  

File Attachment:

File Name: limesurvey...2253.lss
File Size:30 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: boshra.m

Please Log in to join the conversation.

  • boshra.m
  • boshra.m's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
1 year 5 months ago #233696 by boshra.m
Replied by boshra.m on topic Making a row exclusive
Thank you thank you!!

Please Log in to join the conversation.

  • boshra.m
  • boshra.m's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
1 year 5 months ago #233718 by boshra.m
Replied by boshra.m on topic Making a row exclusive
Ah now I was wondering however instead of making it so that the respondent has to check at least one box per row, how would I go about making it that they have to check one box per column?

I would do array but column but I need the checkbox layout.

Thank you!!

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 5 months ago #233726 by tpartner
Replied by tpartner on topic Making a row exclusive
This has nothing to do with "Making a row exclusive". Please open a new thread for new topics.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: boshra.m

Please Log in to join the conversation.

More
1 year 2 months ago #240080 by LeldeAv
Replied by LeldeAv on topic Making a row exclusive
What modifications would I need to make to this script in order to get the same result but for last column? 

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 2 months ago #240094 by Joffm
Replied by Joffm on topic Making a row exclusive

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

Lime-years ahead

Online-surveys for every purse and purpose