Welcome to the LimeSurvey Community Forum

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

Workaround Toggle visibility of groups

  • Stan
  • Stan's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
8 years 1 month ago - 8 years 1 month ago #133226 by Stan
Hi all,

i tested several times this workaround but it doesn't look like it should; and i would be glad to know what i'm doing wrong. Thanks for help.

P.S: My test-Survey is attached.

File Attachment:

File Name: FTO.lss
File Size:25 KB


Using LS Version 2.06+ Build 151018
Attachments:
Last edit: 8 years 1 month ago by Stan. Reason: Correction
The topic has been locked.
More
8 years 1 month ago #133234 by jelo
Replied by jelo on topic Workaround Toggle visibility of groups
The workaround seems to be last tested under a 1.9X version.
Since I always use group-mode i was never interested in these kind of workarounds.

Tpartner might know the answer if the workaround is still working under 2.06 and higher.

The meaning of the word "stable" for users
www.limesurvey.org/forum/development/117...ord-stable-for-users
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 1 month ago #133267 by tpartner
Replied by tpartner on topic Workaround Toggle visibility of groups
There is a JS error at line 51 of the script caused by Expression Manager (which didn't exist in version when the workaround was developed).

This line:
Code:
$('.surveywelcome').css({'margin-bottom':'10px'});

Needs to be this:
Code:
$('.surveywelcome').css({
  'margin-bottom':'10px'
});

I have updated the workaround - manual.limesurvey.org/Workarounds:_Manip...visibility_of_groups

Here's a working version of your test survey:

File Attachment:

File Name: limesurvey...4473.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 following user(s) said Thank You: Stan
The topic has been locked.
  • Stan
  • Stan's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
8 years 1 month ago #133310 by Stan
Replied by Stan on topic Workaround Toggle visibility of groups
Thanks Tpartner, it works!

I also struggled with this workaround . Maybe it needs a correction too...
Here an example of my Array.

File Attachment:

File Name: Multi.lss
File Size:18 KB
Attachments:
The topic has been locked.
  • Stan
  • Stan's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
8 years 1 month ago #133370 by Stan
Replied by Stan on topic Workaround Toggle visibility of groups
I've actually found in the Forum a nice solution for the Workaround i mentioned (Variable length Array).
Here is the interesting thread.

The following code works well for me too:
Code:
<script type="text/javascript" charset="utf-8">    
  $(document).ready(function(){
    variableLengthTextArray({QID});
  })
 
  function variableLengthTextArray(qID) {  
 
    var thisQuestion = $('#question'+qID);
    thisQuestion.addClass('variable-length-text-array');
 
    // Insert some styles
    $('<style type="text/css">\
      .hidden {\
        display: none !important;\
        visibility: hidden !important;\
      }\
      .expandable-control:disabled {\
      opacity: 0.3;\
      }\
    </style>').appendTo('head');
 
    // Insert the controls
    $('table.subquestions-list', thisQuestion).after('<div class="expandable-controls-wrapper">\
                              <button type="button" class="expandable-control remove">-</button>\
                              <button type="button" class="expandable-control add">+</button>\
                            </div>');
 
    // Click events
    $('.expandable-control.add', thisQuestion).click(function (event) {
      $('tr.subquestion-list.hidden:first', thisQuestion).removeClass('hidden').addClass('shown');
      handleArrayControls();
      $('.expandable-control', thisQuestion).blur();
    });
    $('.expandable-control.remove', thisQuestion).click(function (event) {
      $('tr.subquestion-list.shown:last', thisQuestion).removeClass('shown').addClass('hidden');
      clearRows();
      handleArrayControls();
      $('.expandable-control', thisQuestion).blur();
    });
 
    function handleArrayControls() {
      $('.expandable-control.remove', thisQuestion).prop('disabled', true);
      if($('tr.subquestion-list:visible', thisQuestion).length > 1) {
        $('.expandable-control.remove', thisQuestion).prop('disabled', false);
      }
      $('.expandable-control.add', thisQuestion).prop('disabled', false);
      if($('tr.subquestion-list:visible', thisQuestion).length == $('tr.subquestion-list', thisQuestion).length) {
        $('.expandable-control.add', thisQuestion).prop('disabled', true);
      }
    }
 
    function clearRows() {
      $('tr.subquestion-list.hidden input:text', thisQuestion).val('');
    }
 
    // Initially shown rows
    $('tr.subquestion-list:eq(0)', thisQuestion).addClass('shown');
    $('tr.subquestion-list:gt(0)', thisQuestion).addClass('hidden');
    $('tr.subquestion-list input:text', thisQuestion).filter(function () {return !!this.value;}).closest('tr.subquestion-list').addClass('answered-row');
    var thisQTable = $('table.subquestions-list', thisQuestion);
    var thisQRows = $('.answered-row', thisQuestion);
    var lastAnsweredRow = $('.answered-row:last', thisQuestion);
    var lastAnsweredIndex = $('tr.subquestion-list', thisQTable).index(lastAnsweredRow);
    $('tr.subquestion-list:lt('+(lastAnsweredIndex+1)+')', thisQuestion).removeClass('hidden').addClass('shown');
    handleArrayControls();
  }
</script>
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose