Welcome to the LimeSurvey Community Forum

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

Fix items in the end for 'Multiple + Comments' question

  • evhenii_access
  • evhenii_access's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 weeks 9 hours ago #270455 by evhenii_access
Please help us help you and fill where relevant:
Your LimeSurvey version:   LimeSurvey Cloud Version 6.13.3
Own server or LimeSurvey hosting:   LimeSurvey hosting
Survey theme/template:  Bootswatch

==================For ‘Multiple + Comments’ question with randomized answers, I need to fix positions of 2 answers (Other and None) in the end of the list. I already have 3 variants of script from this forum: #1 and #2 by Tony Partner, #3 source not specified.  All 3 variants work fine for ‘Multiple’-type question, but none works for ‘Multiple + Comments’.    Attached is export of test survey – with all 3 variants used for ‘Multiple + Comments’ and for ‘Multiple’.

File Attachment:

File Name: limesurvey...1239.lss
File Size:78 KB
Please help to adjust the code, so that it works for ‘Multiple + Comments’ question, and so that I can fix positions for two answers (Other and None), not just one (None).   


Below are the variants of script I found and tried:     Variant 1:<script type="text/javascript" data-author="Tony Partner">    $(document).on('ready pjax:scriptcomplete',function(){        // The subquestion codes to fix at the end        var fixedCodes = [ '5'];               // Identify this question        var qID = '{QID}';        var thisQuestion = $('#question'+qID);        var itemsLength = $('.answer-item', thisQuestion).length;    var offset = 1;    if($('.answer-item[id$="X'+qID+'other"]', thisQuestion).length > 0) {      offset = 2;    }         // Move the fixed items        $.each(fixedCodes, function(i, code) {            var thisItem = $('.answer-item[id$="X'+qID+code+'"]', thisQuestion);            var replacedItem = $('.answer-item:eq('+(itemsLength-i-offset)+')', thisQuestion);            $(thisItem).before(replacedItem);            $('.answers-list > ul:last', thisQuestion).append(thisItem);        });    });</script>
 Variant 2:<script type="text/javascript" data-author="Tony Partner">  $(document).on('ready pjax:scriptcomplete',function(){    var fixedItems = ;    //// NO EDITING REQUIRED BELOW HERE ////    // Identify this question    var thisQuestion = $('#question{QID}');    $.each(fixedItems, function(e, code) {      $('li[id$="'+code+'"]').appendTo($('.answers-list', thisQuestion));    });  });</script>



 Variant 3:<script type='text/javascript'>/* Place option at the end of the randomized list */$(document).ready(function() {var move_element="5";/* Please do NOT change the lines below */var move_element="javatbd{SGQ}"+move_element;$("#"+move_element).insertAfter("#question{QID} .answers-list .answer-item:last-child");});</script> 

 

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 weeks 6 days ago - 2 weeks 6 days ago #270463 by tpartner
This script in the source of a Multiple choice with comments type question will  fix the sub-questions defined in the fixedCodes variable at the bottom of the list.

  
Code:
<script type="text/javascript" data-author="Tony Partner">
 
    $(document).on('ready pjax:scriptcomplete',function(){
 
        // The subquestion codes to fix at the end
        var fixedCodes = ['4', '5'];
 
        // Identify this question
        var qID = '{QID}';
        var thisQuestion = $('#question'+qID);
 
        var itemsLength = $('li[id^="javatbd"]', thisQuestion).length;
 
        // Move the fixed items
        $.each(fixedCodes, function(i, code) {
            var thisItem = $('li[id$="X'+qID+code+'"]', thisQuestion);
            if($('li[id$="X'+qID+'other"]', thisQuestion).length > 0) {
                $('li[id$="X'+qID+'other"]', thisQuestion).before(thisItem);
            }
            else {
                $('ul.ls-answers:last', thisQuestion).append(thisItem);
            }
        });
 
    });
</script>

Sample survey attached:  

File Attachment:

File Name: limesurvey...9(1).lss
File Size:51 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 2 weeks 6 days ago by tpartner.

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose