Welcome to the LimeSurvey Community Forum

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

Randomized array of checkboxes with exclusive row at the bottom

  • paulfiner
  • paulfiner's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
3 years 1 month ago #227344 by paulfiner
Please help us help you and fill where relevant:
Your LimeSurvey version: 3.25.17
Own server or LimeSurvey hosting:Own server
Survey theme/template: Fruity
==================
I've used the javascript provided by TPartner here:  link
to make the last row of an array of checkboxes become exclusive which works fine but the client would like to randomise the options and keep 'None of these' anchored at the bottom.
Is that possible?

Cheers,
Paul

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 1 month ago #227349 by tpartner
Oh my, very old scripts...

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

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

  • paulfiner
  • paulfiner's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
3 years 1 month ago #227350 by paulfiner
Hi Tony,
I have attached an LSS file with just that question. I currently randomise the columns and the exclusive row at the bottom works fine but as mentioned they would like to randomise the rows too.

Cheers,
Paul
 

Please Log in to join the conversation.

  • paulfiner
  • paulfiner's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
3 years 1 month ago #227355 by paulfiner
I've just realised that the question is set up so that each row must have an answer.
I need it so that each column must have an answer instead but the array by column question type only allows for single choice answers. Is this do-able?

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 1 month ago #227356 by tpartner
If you prefix the X and Y scale sub-question codes with "X" and "Y" (which you should always do), question validation like this should work:

Code:
count(self.sq_X1) > 0
AND
count(self.sq_X2) > 0
AND
count(self.sq_X3) > 0
AND
count(self.sq_X4) > 0

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 1 month ago #227358 by tpartner
In an array-numbers-checkboxes question with "Random order" set to "Yes", this script will fix the position of the y-scale sub-question defined by the fixedSqCode variable in the last position and will render the last row as exclusive.

The attached survey also has the question validation outlined above.

Code:
<script type="text/javascript" data-author="Tony Partner">
  $(document).ready(function() {
 
    var qID = '{QID}';
    var thisQuestion = $('#question'+qID);
 
    // Fix the bottom row position
    var fixedSqCode = 'Y14';
    var fixedRow = $('tr[id^="javatbd"][id$="X'+qID+fixedSqCode+'"]', thisQuestion);
    $('table.subquestion-list tbody:last', thisQuestion).append(fixedRow);
 
    // Fix up the row classes
    var rowClass = 1;
    $('tr[id^="javatbd"]', thisQuestion).removeClass('ls-even ls-odd').each(function(i) {
      if(i%2 == 0) {
        $(this).addClass('ls-even');
      }
      else {
        $(this).addClass('ls-odd');
      }
    });
 
    // Add column-specific classes
    $('tr.subquestion-list', thisQuestion).each(function(i) {
      $('> *', this).each(function(i) {
        $(this).addClass('column-'+i).attr('data-column', i);
      });
    });
 
    // Add some classes to the checkbox cells
    $('td.checkbox-item', thisQuestion).addClass('normal-opt');
    $('tr[id^="javatbd"]:last td.checkbox-item', thisQuestion).removeClass('normal-opt').addClass('exclusive-opt');
 
    // A listener on the checkboxes
    $('td.checkbox-item input[type="checkbox"]', thisQuestion).change(function (event) {
      handleExclusive($(this).closest('td'));
    });
 
    function handleExclusive(thisCell) {
 
      var thisColumn = $(thisCell).attr('data-column');
      var thisCheckBox = $('input[type="checkbox"]', thisCell);
 
      // Uncheck the appropriate boxes in a column
      $('.checkbox-item[data-column="'+thisColumn+'"] input[type="checkbox"]').prop('disabled', false);
      if ($(thisCell).hasClass('normal-opt') &amp;&amp; $(thisCheckBox).is(':checked')) {
        $('.exclusive-opt[data-column="'+thisColumn+'"] input:hidden').val('');
        $('.exclusive-opt[data-column="'+thisColumn+'"] input[type="checkbox"]').prop('checked', false).trigger('change');
      }
      else if ($(thisCheckBox).is(':checked')) {
        $('.normal-opt[data-column="'+thisColumn+'"] input:hidden').val('');
        $('.normal-opt[data-column="'+thisColumn+'"] input[type="checkbox"]').prop('checked', false).trigger('change').prop('disabled', true);
      }
    }
  });
</script>

Sample survey attached: 

File Attachment:

File Name: limesurvey...2(2).lss
File Size:30 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

  • paulfiner
  • paulfiner's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
3 years 1 month ago #227359 by paulfiner
That's great Tony, many thanks as always!

Cheers,
Paul

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose