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

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 3 months ago - 3 years 3 months ago #208865 by tpartner
Apply the exclusive script before the fixed-row 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);
        });
      }
    });
 
    // The subquestion code to place in the last position
    var fixedCode = 'A20';
 
    // Move the "fixed" row to the end
    $('table.subquestion-list tbody:last', thisQuestion).append($('tr[id$="X'+qID+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>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 3 years 3 months ago by tpartner.
The topic has been locked.
  • surveySn
  • surveySn's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
3 years 3 months ago #208868 by surveySn
Hi Tony


If random order is used

Can't fixed the last row,

File Attachment:

File Name: limesurvey... (1).lss
File Size:30 KB
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 3 months ago #208891 by tpartner
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);
        });
      }
    });
 
    // The subquestion code to place in the last position
    var fixedCode = 'A20';
 
    // Move the "fixed" row to the end
    $('table.subquestion-list tbody:last', thisQuestion).append($('tr[id$="X'+qID+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>

Sample survey attached:

File Attachment:

File Name: limesurvey...9278.lss
File Size:31 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 3 months ago #208929 by surveySn
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose