Welcome to the LimeSurvey Community Forum

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

How can I use exclusion filter?

  • giovbod
  • giovbod's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 1 month ago #211652 by giovbod
How can I use exclusion filter? was created by giovbod
I setup a question a number array question with checkbox style.
I need for each row and for each column, if the last option is chosen, any other option is deselected.

In the example survey, if I select "nessuno" in row "uno", I want cells (SelezA, SelezB and SelezC in that row be unchecked (if previously checked).
The same if I select "zero" in column "SelezA".

I guess the exclusion array filter could be used, but I don't know how.

Thank you in advance
GB 

File Attachment:

File Name: test per f...ione.lss
File Size:19 KB
 
   
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 1 month ago #211653 by tpartner
Replied by tpartner on topic How can I use exclusion filter?

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 #212095 by giovbod
Replied by giovbod on topic How can I use exclusion filter?
Thanks.
Actually I tried this solution and it works fine. Meaning each cell in the last row disables the whole column.
I tried to modify the script so that it does also the same with the last column, but it doesn't work.
Any chance someone with better javascript can modify the script ?

Thanks
GB 
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 1 month ago #212096 by tpartner
Replied by tpartner on topic How can I use exclusion filter?
Okay, so the last item in each row is exclusive for that row AND the last item in each column is exclusive for that column. Correct?

If so, do you want to hide the Zero/Nessuno checkbox? (Is it necessary?)

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 #212242 by giovbod
Replied by giovbod on topic How can I use exclusion filter?
If possible ... yes
Thanks
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 1 month ago #212247 by tpartner
Replied by tpartner on topic How can I use exclusion filter?
This script will make both the last column and the last row exclusive and will remove the checkbox from the last-row/last-column cell.

Code:
<script type="text/javascript" data-author="Tony Partner">
 
  $(document).on('ready pjax:scriptcomplete',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:last-child', thisQuestion).addClass('exclusive-item row-exclusive');
    $('tr.subquestion-list:last .answer-item', thisQuestion).addClass('exclusive-item column-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 thisColumn = $(thisCell).attr('data-column');
 
        // Define items to be unchecked
        excludeCells = $('.exclusive-item[data-column="'+thisColumn+'"], .exclusive-item[data-row="'+thisRow+'"]');
        if(thisCell.hasClass('row-exclusive')) {
          excludeCells = $('.answer-item[data-row="'+thisRow+'"]').not(thisCell);
        }
        if(thisCell.hasClass('column-exclusive')) {
          excludeCells = $('.answer-item[data-column="'+thisColumn+'"]').not(thisCell);
        }
 
        // Uncheck those items
        $(excludeCells).each(function(i) {          
          $('input:hidden', this).val('');
          $(':checkbox', this).prop('checked', false).trigger('change');
        });
      }
    }
 
    // Remove checkbox in last row, last column
    $('tr.subquestion-list:last .answer-item:last-child *', thisQuestion).remove();
  });
</script>

Sample survey attached:  

File Attachment:

File Name: limesurvey...1(2).lss
File Size:22 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: giovbod
The topic has been locked.
  • giovbod
  • giovbod's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 1 month ago #212258 by giovbod
Replied by giovbod on topic How can I use exclusion filter?
Thank you very much.
And double thank you for answering so quickly
The topic has been locked.
  • giovbod
  • giovbod's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 1 month ago #212344 by giovbod
Replied by giovbod on topic How can I use exclusion filter?
Tony,
I know I am abusing your kindness, but I had to change the question.
Now the array has some rows and 4 columns.
I need, per each row, to have either one of the first columns (or both) or one of the last two.
That is, these are the only configurations ok:
1  0  0  0
1  1  0  0
0  1  0  0
0  0  1  0
0  0  0  1
I tried to modify the script you wrote, but obviously my skills are not enough. 
With the exclusivity this configured, I will set a relevance equation in the next question, so that it is displayed if only the last two columns have been selected (i.e. if the answers are the last two exapmles I wrote). I plan to use something like sum(Q1_SQ001_SQ00C,Q1_SQ001_SQ00D,Q1_SQ002_SQ00C,Q1_SQ002_SQ00D,Q1_SQ003_SQ00C,Q1_SQ003_SQ00D)==3 unless there is a way to sum all the values for the last two columns ...
Thank you again
G.
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 1 month ago - 3 years 1 month ago #212359 by Joffm
Replied by Joffm on topic How can I use exclusion filter?
You may validate:

If the sum of a row is "2" the last two columns have to be empty - or the sum is "1".
E.g. for each row.
(sum(self.sq_Y001)==2 and is_empty(self.sq_Y001_X003)  and is_empty(self.sq_Y001_X004)) or sum(self.sq_Y001)==1





Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 3 years 1 month ago by Joffm.
The topic has been locked.
  • giovbod
  • giovbod's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 1 month ago #212361 by giovbod
Replied by giovbod on topic How can I use exclusion filter?
Thank you Joffm.
However I'd rather proceed with the exclusivity.
But I don't know how to modify the javascript ...
:o(
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 1 month ago #212363 by Joffm
Replied by Joffm on topic How can I use exclusion filter?

sum(Q1_SQ001_SQ00C,Q1_SQ001_SQ00D,Q1_SQ002_SQ00C,Q1_SQ002_SQ00D,Q1_SQ003_SQ00C,Q1_SQ003_SQ00D)==3 unless there is a way to sum all the values for the last two columns ...


Of course there is a way.
Manual:
[url] manual.limesurvey.org/ExpressionScript_-....22that.22_variables [/url]

sum(that.Q1.sq_C,that.Q1.sq_D) == x

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
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 #212370 by giovbod
Replied by giovbod on topic How can I use exclusion filter?
Thank you for your answer. And Thank you for the link, I couldn't find the reference to study.
Now I only need to find a way to modify the script tpartner gave me and then I can publish the survey...
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose