Welcome to the LimeSurvey Community Forum

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

Modify Subanswers' indent

  • helasz
  • helasz's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 week 2 days ago #268732 by helasz
Modify Subanswers' indent was created by helasz
Hi All,

My LimeSurvey version: 6.10
Own server or LimeSurvey hosting: Docker
Survey theme/template: (slightly modified) Bootswatch
====================================
I would like to increase the indent of answers within Multiple Choice question type automatically based on answer code (ie if the answer code begins by 'SA' /SubAnswer/ for example then increase the indent, but do nothing else).

[I did browse the Limesurvey Javascript documentation and the LS forum, I know about the hide/show increased indentation solution which do require to modify manually the javascript inserting the secondary and tertiary answer codes. I do not need to hide any subanswer, I am perfectly happy by showing them, however with increased indentation.]

Example:
answer code      subanswer
A1                      Primary answer 1
A2                      Primary answer 2
SA21                      Secondary answer 1 to Primary answer 2
SA22                      Secondary answer 2 to Primary answer 2
A3                      Primary answer 3
...

My failing code attempt is this:
    $(document).on('ready pjax:scriptcomplete',function() {                                                       
      // Select the secondary answers - this should work according to the LS-Javascript doc
      var secAnswers = $(self.sq_SA);
     // should I here somehow iterate through the whole secAnswers Array and set CSS one by one?
      secAnswers.css({ 'margin-left':'2.5em' });
    });

 

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 week 2 days ago - 1 week 2 days ago #268733 by Joffm
Replied by Joffm on topic Modify Subanswers' indent
Here a short solution to only indent the subquestions that start with a certain code ("SA")
Code:
<script type="text/javascript" charset="utf-8">
  $(document).on('ready pjax:scriptcomplete',function(){
 
    //Identify this question
    var thisQuestion = $('#question{QID}');
    $('li.answer-item', thisQuestion).each(function(i) {
            ansCode=($(this).attr('id').split('X{QID}')[1]);
            if(ansCode.substring(0, 2)=='SA') {       
              $(this).css({
                 'margin-left': '2.5em'
               });
            }
    });
  });
</script>

  
Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 1 week 2 days ago by Joffm.

Please Log in to join the conversation.

  • helasz
  • helasz's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 week 1 day ago #268735 by helasz
Replied by helasz on topic Modify Subanswers' indent
That is perfect! Thank you Joffm!
The following user(s) said Thank You: jonas.jau

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 week 1 day ago - 1 week 1 day ago #268740 by Joffm
Replied by Joffm on topic Modify Subanswers' indent
Hi,
and if you want to use the "old", "known" script with the better handling of these dependend subquestions just exchange the "hardcoded" subquestions
Code:
      dependantCheckboxes(
      {QID},
      ['SQ1', 'SQ2', 'SQ3', 'SQ4'], // First-level sub-question codes
      ['SQ11', 'SQ12', 'SQ21', 'SQ22', 'SQ31', 'SQ32', 'SQ33', 'SQ41', 'SQ42', 'SQ43'], // Second-level sub-question codes
      ['SQ111', 'SQ112', 'SQ113', 'SQ321', 'SQ322', 'SQ323', 'SQ411', 'SQ412'] // Third-level sub-question codes
    );


with this
Code:
    var thisQuestion = $('#question{QID}');
    var level1=;
    var level2=;
    var level3=;
    $('li.answer-item', thisQuestion).each(function(i) {
            ansCode=($(this).attr('id').split('X{QID}')[1]);
            if(ansCode.substring(0, 2)=='SA') {
              level2.push(ansCode);
            }
            else if(ansCode.substring(0, 2)=='SB') {
              level3.push(ansCode);
            }
            else {
              level1.push(ansCode);
            }
    });
 
    dependantCheckboxes(
      {QID},
      level1, // First-level sub-question codes
      level2, // Second-level sub-question codes
      level3  // Third-level sub-question codes
    );



Joffm
 

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 1 week 1 day ago by Joffm.

Please Log in to join the conversation.

  • helasz
  • helasz's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 week 1 day ago - 1 week 1 day ago #268741 by helasz
Replied by helasz on topic Modify Subanswers' indent
Wow! You have read in my thoughts. That is plusquamperfect!!! You have saved my days, not only today. Thank you!
Last edit: 1 week 1 day ago by helasz.

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose