Welcome to the LimeSurvey Community Forum

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

How can I use exclusion filter?

  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 1 month ago #212379 by tpartner
Replied by tpartner on topic How can I use exclusion filter?
Is the last row still to exclude all others in the same column?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • giovbod
  • giovbod's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 1 month ago #212388 by giovbod
Replied by giovbod on topic How can I use exclusion filter?
Nope, I need each of the last two columns in each row should exclude the others (and vice versa).
That is (using the examples Joffm pictured):
These examples are correct:
https://forums.limesurvey.org/forum/attachment/24238
While here's there's a problem:
https://forums.limesurvey.org/forum/attachment/24239as in subquestion 5 both column C and D are selected.
Am I too confusing?
Thank you in advance
G.
 
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 1 month ago #212389 by tpartner
Replied by tpartner on topic How can I use exclusion filter?
In that case, this will render the first-2 and the last-2 columns exclusive within a row:

Code:
<script type="text/javascript" data-author="Tony Partner">
 
  $(document).ready(function() {
 
    var thisQuestion = $('#question{QID}');
 
    // Add column and row specific classes
    $('tr.subquestion-list', thisQuestion).each(function(i) {
      var rowIndex = i;
      $('th, td', this).each(function(i) {
        $(this).addClass('column-'+i+' row-'+rowIndex).attr('data-column', i).attr('data-row', rowIndex);
      });
    });
 
    // Add some classes to the checkbox cells
    $('tr.subquestion-list .answer-item:nth-child(n+4)', thisQuestion).addClass('exclusive-item row-exclusive set-2').attr('data-set', 2);
    $('tr.subquestion-list .answer-item:not(.set-2)', thisQuestion).addClass('exclusive-item row-exclusive set-1').attr('data-set', 1);
 
    // A listener on the checkboxes
    $('.answer-item input[type="checkbox"]', thisQuestion).change(function (event) {
      handleExclusive($(this).closest('.answer-item'));
    });
 
    function handleExclusive(thisCell) {
 
      var thisCheckBox = $(':checkbox', thisCell);
 
      if(thisCheckBox.is(':checked')) {
 
        var thisRow = $(thisCell).attr('data-row');
        var thisColumn = $(thisCell).attr('data-column');
        var thisSet = $(thisCell).attr('data-set');
 
        var excludeCells = $('.answer-item[data-row="'+thisRow+'"]').not('[data-set="'+thisSet+'"]');
 
        // Uncheck those items
        $(excludeCells).each(function(i) {          
          $('input:hidden', this).val('');
          $(':checkbox', this).prop('checked', false).trigger('change');
        });
      }
    }
  });
</script>

Sample survey attached: 

File Attachment:

File Name: limesurvey...9511.lss
File Size:26 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • giovbod
  • giovbod's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 1 month ago #212390 by giovbod
Replied by giovbod on topic How can I use exclusion filter?
Thank you.
But I need column 3 and 4 to be exclusive among them.
To summarize:
A B C D
R1 1 0 0 0
R2 1 1 0 0
R3 0 0 1 0
R4 0 0 0 1
all these rows are ok, but
R5 0 0 1 1
is not ok as both column C and D are 1
Thanks
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 1 month ago #212420 by tpartner
Replied by tpartner on topic How can I use exclusion filter?
Try this (untested):

Code:
<script type="text/javascript" data-author="Tony Partner">
 
  $(document).ready(function() {
 
    var thisQuestion = $('#question{QID}');
 
    // Add column and row specific classes
    $('tr.subquestion-list', thisQuestion).each(function(i) {
      var rowIndex = i;
      $('th, td', this).each(function(i) {
        $(this).addClass('column-'+i+' row-'+rowIndex).attr('data-column', i).attr('data-row', rowIndex);
      });
    });
 
    // Add some classes to the checkbox cells
    $('.answer-item:nth-child(2), .answer-item:nth-child(3)', thisQuestion).addClass('exclusive-item row-exclusive set-1').attr('data-set', 1);
    $('.answer-item:nth-child(4)', thisQuestion).addClass('exclusive-item row-exclusive set-2').attr('data-set', 2);
    $('.answer-item:nth-child(5)', thisQuestion).addClass('exclusive-item row-exclusive set-3').attr('data-set', 3);
 
    // A listener on the checkboxes
    $('.answer-item input[type="checkbox"]', thisQuestion).change(function (event) {
      handleExclusive($(this).closest('.answer-item'));
    });
 
    function handleExclusive(thisCell) {
 
      var thisCheckBox = $(':checkbox', thisCell);
 
      if(thisCheckBox.is(':checked')) {
 
        var thisRow = $(thisCell).attr('data-row');
        var thisColumn = $(thisCell).attr('data-column');
        var thisSet = $(thisCell).attr('data-set');
 
        var excludeCells = $('.answer-item[data-row="'+thisRow+'"]').not('[data-set="'+thisSet+'"]');
 
        // Uncheck those items
        $(excludeCells).each(function(i) {          
          $('input:hidden', this).val('');
          $(':checkbox', this).prop('checked', false).trigger('change');
        });
      }
    }
  });
</script>

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: giovbod
The topic has been locked.
  • giovbod
  • giovbod's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 1 month ago #212439 by giovbod
Replied by giovbod on topic How can I use exclusion filter?
Just tried and it works perfectly.
Thank you
G.
The topic has been locked.
  • giovbod
  • giovbod's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 1 month ago #212508 by giovbod
Replied by giovbod on topic How can I use exclusion filter?
Thank you again.
But I need an additional change.
Can you make it so that each of the last two column are exclusive with any column before?
That is, if I have only 3 columns, each column is exclusive
If I have 5 columns, the exclusivity is between the first group of column 1-2-3, the second group of column 4 and the third group of column 5
Does imy request make any sense?
Thanks
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 1 month ago #212539 by tpartner
Replied by tpartner on topic How can I use exclusion filter?
This will render the last two columns exclusive of everything within a row:

Code:
<script type="text/javascript" data-author="Tony Partner">
 
  $(document).ready(function() {
 
    var thisQuestion = $('#question{QID}');
 
    // Add column and row specific classes
    $('tr.subquestion-list', thisQuestion).each(function(i) {
      var rowIndex = i;
      $('th, td', this).each(function(i) {
        $(this).addClass('column-'+i+' row-'+rowIndex).attr('data-column', i).attr('data-row', rowIndex);
      });
    });
 
    // Add some classes to the checkbox cells
    $('.answer-item:nth-last-child(1), .answer-item:nth-last-child(2)', thisQuestion).addClass('exclusive-item row-exclusive')
 
    // A listener on the checkboxes
    $('.answer-item input[type="checkbox"]', thisQuestion).change(function (event) {
      handleExclusive($(this).closest('.answer-item'));
    });
 
    function handleExclusive(thisCell) {
 
      var thisCheckBox = $(':checkbox', thisCell);
 
      if(thisCheckBox.is(':checked')) {
 
        var thisRow = $(thisCell).attr('data-row');
 
        var excludeCells = $('.answer-item.exclusive-item[data-row="'+thisRow+'"]');
        if($(thisCell).hasClass('exclusive-item')) {
          excludeCells = $('.answer-item[data-row="'+thisRow+'"]').not(thisCell);
        }
 
        // Uncheck those items
        $(excludeCells).each(function(i) {          
          $('input:hidden', this).val('');
          $(':checkbox', this).prop('checked', false).trigger('change');
        });
      }
    }
  });
</script>

Sample survey attached: 

File Attachment:

File Name: limesurvey...1(3).lss
File Size:33 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose