Welcome to the LimeSurvey Community Forum

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

Last Option In Array (Numbers) (Checkboxes) column Excludes All Others

  • surveySn
  • surveySn's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
3 years 4 months ago #208762 by surveySn
Hello everyone,
Last Option In Array (Numbers) (Checkboxes) column Excludes All Others
manual.limesurvey.org/Workarounds:_Manip..._Excludes_All_Others
How do it?

I searched the forum and there was no answer to the column.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 4 months ago - 3 years 4 months ago #208764 by tpartner
Do not double-post.

I searched the forum and there was no answer to the column.

- forums.limesurvey.org/forum/can-i-do-thi...-all-others&start=15

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 3 years 4 months ago by tpartner.
The topic has been locked.
  • surveySn
  • surveySn's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
3 years 4 months ago #208766 by surveySn
forums.limesurvey.org/forum/can-i-do-thi...-all-others&start=15
This is row exclusive,

I want to be column exclusive,

could you help me,
Version 3.22.11 + 200330
The topic has been locked.
  • surveySn
  • surveySn's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
3 years 4 months ago #208767 by surveySn
Sorry, I changed my reply,
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 4 months ago #208769 by tpartner

surveySn wrote: This is row exclusive,

I want to be column exclusive

Huh?


Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • surveySn
  • surveySn's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
3 years 4 months ago #208771 by surveySn
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 4 months ago #208789 by tpartner
Oh, an exclusive row...

Can you attach a small sample survey (.lss file) containing only that question?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • surveySn
  • surveySn's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
3 years 4 months ago #208796 by surveySn
SQ007_A and SQ007_B and SQ007_C and SQ007_D and SQ007_E and SQ007_F and SQ007_G It's exclusive

File Attachment:

File Name: limesurvey...3221.lss
File Size:22 KB
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 4 months ago - 3 years 4 months ago #208815 by tpartner
So, to be clear...

Every row is exclusive (only one answer per column) or the last row is exclusive (last row excludes all other answers in the same column)?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 3 years 4 months ago by tpartner.
The topic has been locked.
  • surveySn
  • surveySn's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
3 years 4 months ago #208823 by surveySn
the last row is exclusive (last row excludes all other answers in the same column)
My English is poor and I don't express myself clearly,:kiss:
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 4 months ago #208844 by tpartner
Add this script to the source of the question:

Code:
<script type="text/javascript" charset="utf-8">  
  $(document).on('ready pjax:scriptcomplete',function(){
 
    // Identify this question
    var qID = '{QID}';
    var thisQuestion = $('#question'+qID);
 
    // Assign column-specific attributes and classnames
    $('tr.subquestion-list', thisQuestion).each(function(i) {
      $('> *', this).each(function(i) {
        $(this).attr('data-column', i);
      });
    });
    $('tr.subquestion-list:last td.answer-item', thisQuestion).addClass('exclusive-item');
 
    // A function to un-check boxes
    function resetCheckbox(thisItem) {
      $(':hidden', thisItem).val('');
      $(':checkbox', thisItem).prop('checked', false).trigger('change');
    }
 
    // Listener on the checkboxes
    $(':checkbox', thisQuestion).on('change', function(e) {
      if($(this).is(':checked')) {
        var thisItem = $(this).closest('.answer-item');
        var thisColumn = $(thisItem).attr('data-column');
        var items = $('td.answer-item[data-column="'+thisColumn+'"].exclusive-item', thisQuestion);
        if($(thisItem).hasClass('exclusive-item')) {
          items = $('td.answer-item[data-column="'+thisColumn+'"]:not(.exclusive-item)', thisQuestion);
        }
        $.each(items, function(i, el) {
          resetCheckbox(el);
        });
      }
    });
    });
</script>

Here is a sample survey:

File Attachment:

File Name: limesurvey...1(1).lss
File Size:25 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.
  • surveySn
  • surveySn's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
3 years 4 months ago #208856 by surveySn
Great Tony,

thank you,



I have another question,

I play random sub problems,

fixed the last item,
Code:
<script type="text/javascript" charset="utf-8">  
  $(document).ready(function() {
 
    // The subquestion code to place in the last position
    var fixedCode = 'A20';
 
    // Identify this question
    var q1ID = {QID};
    var thisQuestion = $('#question'+q1ID);
 
    // Move the "fixed" row to the end
    $('table.subquestion-list tbody:last', thisQuestion).append($('tr[id$="X'+q1ID+fixedCode+'"]'));
 
    // Fix up the array row background colours
    $('tr.answers-list', thisQuestion).each(function(i){
      $(this).removeClass('array1 array2').addClass('array'+(2-(i%2)));
    });
 
    });
</script>

Use your script,
Code:
<script type="text/javascript" charset="utf-8">  
  $(document).on('ready pjax:scriptcomplete',function(){
 
    // Identify this question
    var qID = '{QID}';
    var thisQuestion = $('#question'+qID);
 
    // Assign column-specific attributes and classnames
    $('tr.subquestion-list', thisQuestion).each(function(i) {
      $('> *', this).each(function(i) {
        $(this).attr('data-column', i);
      });
    });
    $('tr.subquestion-list:last td.answer-item', thisQuestion).addClass('exclusive-item');
 
    // A function to un-check boxes
    function resetCheckbox(thisItem) {
      $(':hidden', thisItem).val('');
      $(':checkbox', thisItem).prop('checked', false).trigger('change');
    }
 
    // Listener on the checkboxes
    $(':checkbox', thisQuestion).on('change', function(e) {
      if($(this).is(':checked')) {
        var thisItem = $(this).closest('.answer-item');
        var thisColumn = $(thisItem).attr('data-column');
        var items = $('td.answer-item[data-column="'+thisColumn+'"].exclusive-item', thisQuestion);
        if($(thisItem).hasClass('exclusive-item')) {
          items = $('td.answer-item[data-column="'+thisColumn+'"]:not(.exclusive-item)', thisQuestion);
        }
        $.each(items, function(i, el) {
          resetCheckbox(el);
        });
      }
    });
    });
</script>

Not the last row excludes



File Attachment:

File Name: limesurvey...9278.lss
File Size:30 KB
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose