Welcome to the LimeSurvey Community Forum

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

How can I use exclusion filter?

More
5 years 7 months ago #212390 by giovbod
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.
More
5 years 7 months ago #212420 by tpartner
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.
More
5 years 7 months ago #212439 by giovbod
Just tried and it works perfectly.
Thank you
G.
The topic has been locked.
More
5 years 7 months ago #212508 by giovbod
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.
More
5 years 7 months ago #212539 by tpartner
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:32.87 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.
Moderators: tpartner, holch

Lime-years ahead

Online-surveys for every purse and purpose