Welcome to the LimeSurvey Community Forum

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

Exclusive row and column for one answer

  • eniisula
  • eniisula's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
3 years 3 months ago #225877 by eniisula
Exclusive row and column for one answer was created by eniisula
Your LimeSurvey version: Version 5.2.13+220207
==================
On question A.10 which I have attached below, I want the first subquestion in y-scale selected for only one company (all 3 companies are chosen from the previous question). So the first row should be exclusive if one of the companies is selected. Also for that company none of the other subquestions in y-scale must not be selected. So the subquestions in y-scale must not be available for the company that has the first subquestion selected. 
I do not know if I am clear but if anyone can help me achieve this I would be gre.

Thank you in advance everyone!

Please Log in to join the conversation.

  • eniisula
  • eniisula's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
3 years 3 months ago #225896 by eniisula
Replied by eniisula on topic Exclusive row and column for one answer
Basically I want to achieve the 3 cases below. Highlighted with yellow is the row and column I want to be exclusive.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 3 months ago - 3 years 3 months ago #225906 by Joffm
Replied by Joffm on topic Exclusive row and column for one answer
This you can do easily by validation, like
count(self.sq_Y1)==0 or ((self.sq_Y1_X1==1 and count(self.sq_Y1)==1 and count(self.sq_X1)==1) or (self.sq_Y1_X2==1 and count(self.sq_Y1)==1 and count(self.sq_X3)==1) or (self.sq_Y1_X3==1 and count(self.sq_Y1)==1 and count(self.sq_X3)==1) or (self.sq_Y1_X4==1 and count(self.sq_Y1)==1 and count(self.sq_X4)==1) or (self.sq_Y1_X5==1 and count(self.sq_Y1)==1 and count(self.sq_X5)==1) or (self.sq_Y1_X6==1 and count(self.sq_Y1)==1 and count(self.sq_X6)==1)) 

with Y1 as first row of y-axis and X1 - X6 as codes of x-axis.







Neglect the "c: x". Was for testing.

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 3 years 3 months ago by Joffm.
The following user(s) said Thank You: eniisula

Please Log in to join the conversation.

  • eniisula
  • eniisula's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
3 years 3 months ago #225911 by eniisula
Replied by eniisula on topic Exclusive row and column for one answer
Thank you for your reply!

I am still not very familiar with the validation. I adapted it to my question like this:

count(self.sq_S1)==0
or ((self.sq_S1_SQ1==1 and count(self.sq_S1)==1 and count(self.sq_SQ1)==1)
or (self.sq_S1_SQ2==1 and count(self.sq_S1)==1 and count(self.sq_SQ3)==1)
or (self.sq_S1_SQ3==1 and count(self.sq_S1)==1 and count(self.sq_SQ3)==1)
or (self.sq_S1_SQ4==1 and count(self.sq_S1)==1 and count(self.sq_SQ4)==1)
or (self.sq_S1_SQ5==1 and count(self.sq_S1)==1 and count(self.sq_SQ5)==1)
or (self.sq_S1_SQ6==1 and count(self.sq_S1)==1 and count(self.sq_SQ6)==1))


I do not know how to write the validation tip. Only like this it does not seem to work as your screenshots do.

 

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 3 months ago #225912 by tpartner
Replied by tpartner on topic Exclusive row and column for one answer
If you want dynamic handling of the check-boxes, this script will render the check-boxes in the first row exclusive within that row and exclusive within their columns:
Code:
<script type="text/javascript" data-author="Tony Partner">  
  $(document).on('ready pjax:scriptcomplete',function(){
 
    var thisQuestion = $('#question{QID}');
    var firstRow = $('tr.subquestion-list:eq(0)', thisQuestion);
 
    // Listener on the first row checkboxes
    $(':checkbox', firstRow).on('change', function(e){
      $(':checkbox', thisQuestion).prop('disabled', false);
 
      if($(this).is(':checked')) {
        var thisCell = $(this).closest('td');
        var thisIndex = $(thisCell).index();
 
        // Render this checkbox exclusive in this row
        var otherRowCells = $('td.answer-item', firstRow).not(thisCell);        
        $(otherRowCells).each(function(i) {
          $('input[type="hidden"]', this).val('');
          $(':checkbox', this).prop('checked', false).trigger('change');
        });
 
        // Render this checkbox exclusive in this column
        var otherColCells = $('td.answer-item:nth-child('+(thisIndex+1)+')').not(thisCell);        
        $(otherColCells).each(function(i) {
          $('input[type="hidden"]', this).val('');
          $(':checkbox', this).prop('checked', false).trigger('change').prop('disabled', true);
        });
      }
    });
  });
</script>

Sample survey attached: 

File Attachment:

File Name: limesurvey...7194.lss
File Size:41 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: eniisula

Please Log in to join the conversation.

  • eniisula
  • eniisula's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
3 years 3 months ago #225914 by eniisula
Replied by eniisula on topic Exclusive row and column for one answer
Thank you! This was very helpful!

Please Log in to join the conversation.

  • eniisula
  • eniisula's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
3 years 3 months ago #225926 by eniisula
Replied by eniisula on topic Exclusive row and column for one answer
Is it possible to edit this code so the other rows to allow only one of the two answers available to be checked. Basically each row can allow one answer to be checked but multiple answers per column are allowed (without changing what the code you provided before did)

Thank you in advance for your help!

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose