Welcome to the LimeSurvey Community Forum

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

Multiple Choice with headers - advanced

  • tammo
  • tammo's Avatar Topic Author
  • Offline
  • Official LimeSurvey Partner
  • Official LimeSurvey Partner
More
2 years 8 months ago #227060 by tammo
Please help us help you and fill where relevant:
Your LimeSurvey version: 5.3.6
Own server or LimeSurvey hosting: own
Survey theme/template: custom, based on Vanilla
==================
Message for Joffm:

Using your great manual at  www.mafopartner.de/lime/Tutorial_Mehrfach.pdf I tried to define a MC questions with headers. I succeeded, but I want to go 1 step further: would it be possible to have all headings start on a new line (as it is now) and show the answer items under the headings in 4 columns?

File Attachment:

File Name: mcwithheaders.lss
File Size:57 KB


Thanks in advance,

Tammo ter Hark


Tammo ter Hark at Respondage
For Limesurvey reporting, education and customized themes
respondage.nl

Please Log in to join the conversation.

  • tammo
  • tammo's Avatar Topic Author
  • Offline
  • Official LimeSurvey Partner
  • Official LimeSurvey Partner
More
2 years 8 months ago #227077 by tammo
Replied by tammo on topic Multiple Choice with headers - advanced
Even more advanced: now with several "other" options, using another technique as described by Joffm.
I guess the column structure could help (perhaps), but may also make the respondent loose oversight.

 

File Attachment:

File Name: mcwithheaders2.lss
File Size:69 KB


Tammo ter Hark at Respondage
For Limesurvey reporting, education and customized themes
respondage.nl

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 8 months ago #227081 by Joffm
Replied by Joffm on topic Multiple Choice with headers - advanced
Oh , thank you, Tammo,

Always remember:
I have only very basic knowledge of css and javascript.

I don't want to adorn myself with borrowed plumes.
Nearly everything I show here is adapted from others, mainly Tony.

Joffm
 

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

  • tammo
  • tammo's Avatar Topic Author
  • Offline
  • Official LimeSurvey Partner
  • Official LimeSurvey Partner
More
2 years 8 months ago #227086 by tammo
Replied by tammo on topic Multiple Choice with headers - advanced
Yes, I could see that you used two different ways of coding, but since my knowledge is even less than yours (in Holland we say: in the land of the blind, the man with one eye is king), a did not adapt that, because I might run into problems.


Tammo ter Hark at Respondage
For Limesurvey reporting, education and customized themes
respondage.nl

Please Log in to join the conversation.

  • tammo
  • tammo's Avatar Topic Author
  • Offline
  • Official LimeSurvey Partner
  • Official LimeSurvey Partner
More
2 years 8 months ago #227088 by tammo
Replied by tammo on topic Multiple Choice with headers - advanced
Thinking about this: it would be great if you could code the subquestions in such a way, that you can use the Javascript to look at the question codes in stead of the order.

So for example: give all header a subquestion code like H(n) and all answers with the "other" possibility a subquestion code starting with "oth".

The javascript could then possibly act on all subquestions with code starting with H or SQ (for "normal" subquestions) and the script would also work when you expand the list with new subquestions.


Tammo ter Hark at Respondage
For Limesurvey reporting, education and customized themes
respondage.nl

Please Log in to join the conversation.

  • tammo
  • tammo's Avatar Topic Author
  • Offline
  • Official LimeSurvey Partner
  • Official LimeSurvey Partner
More
2 years 8 months ago #227090 by tammo
Replied by tammo on topic Multiple Choice with headers - advanced
this could be done when the subquestion code is also added as a css class to the answer item, I guess. This could be convenient for several Javascripts....


Tammo ter Hark at Respondage
For Limesurvey reporting, education and customized themes
respondage.nl

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 8 months ago #227102 by tpartner
Replied by tpartner on topic Multiple Choice with headers - advanced
Yes, targeting the sub-question codes would be a little more user-friendly.

I'll put something together today as time allows...

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
2 years 8 months ago #227119 by tpartner
Replied by tpartner on topic Multiple Choice with headers - advanced
Here is a script and some CSS that, when placed in the source of a multiple-choice-with-comments type question, will do the following:

1) Convert sub-questions with codes starting with the headerRowPrefix into sub-header rows.
2) Move the sub-questions into columns on larger screens.
3) Remove the text inputs in all sub-questions with codes not starting with the textRowPrefix.

JavaScript:

Code:
<script type="text/javascript" data-author="Tony Partner">  
 
  $(document).on('ready pjax:scriptcomplete',function(){
 
    // Identify this question
    var qID = '{QID}';
    var thisQuestion = $('#question'+qID);
 
 
    /****** HEADER ROWS ******/
 
    // Find the header rows
    var headerRowPrefix = 'h';    
    var headerRows = $('li[id^="javatbd"]', thisQuestion).filter(function() {
      return $(this).attr('id').includes('X'+qID+headerRowPrefix+'');
    });
 
    // Loop through the header rows
    $(headerRows).each(function(i) {
      // Assign a class name
      $(this).addClass('inserted-header-row')
      // Move the label
      .prepend($('label.control-label:eq(0)', this))
      // Remove unecessary elements
      .find('input, div').remove();
    });  
 
 
    /****** ANSWERS INTO COLUMNS ******/
 
    // Number of columns to display (max 4)
    var columns = 4;
 
    thisQuestion.addClass('with-inserted-columns columns-'+columns+'');
 
 
    /****** REMOVE SOME TEXT INPUTS ******/
 
    // Find the rows to keep text inputs
    var textRowPrefix = 'oth';    
    var textRows = $('li[id^="javatbd"]', thisQuestion).filter(function() {
      return $(this).attr('id').includes('X'+qID+textRowPrefix+'');
    });
 
    // Remove text inputs from all except those rows
    $('li[id^="javatbd"]', thisQuestion).not(textRows).find('div.text-item').remove();
  });
</script>

CSS:

Code:
<style type="text/css" data-author="Tony Partner">
 
  li.inserted-header-row {
    float: none;
    clear: both;
    flex: 0 0 100%;
  }
 
  li.inserted-header-row label {
    padding-left: 15px;
    padding-right: 15px;
    font-weight: bold;
  }
 
  li.inserted-header-row label::before,
  li.inserted-header-row label::after{
    display: none;
  }
 
  @media only screen and (min-width: 768px) {
 
    .with-inserted-columns ul.ls-answers {
      display: flex;
      flex-flow: row wrap;
    }
 
    .with-inserted-columns ul.ls-answers li {
      margin: 0 0 1em 0;
      padding: 0 15px 0 0;
    }
 
    .with-inserted-columns.columns-2 ul.ls-answers li { flex: 0 0 50%; }
    .with-inserted-columns.columns-3 ul.ls-answers li { flex: 0 0 33%; }
    .with-inserted-columns.columns-4 ul.ls-answers li { flex: 0 0 25%; }
 
    .with-inserted-columns ul.ls-answers li.inserted-header-row {
      flex: 0 0 100%;
      padding: 0;
    }
 
    .with-inserted-columns ul.ls-answers li > div {
      float: none;
      width: auto;
    }
 
    .with-inserted-columns ul.ls-answers li label {
      text-align: left;
    }
 
    .with-inserted-columns ul.ls-answers li input[type="text"] {
      margin-top: 0.25em;
    }
  }
</style>



Sample survey attached: 

File Attachment:

File Name: limesurvey...9(3).lss
File Size:66 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.

More
1 year 9 months ago #240942 by blocka
Replied by blocka on topic Multiple Choice with headers - advanced
I'm so glad I found this post, as the solution is just what I needed.
I did try setting :
var columns = 1;
and it instead shows the questions in two columns. Any chance of being able to show this question format in 1 column?

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 9 months ago - 1 year 9 months ago #240946 by Joffm
Replied by Joffm on topic Multiple Choice with headers - advanced
Well, this was specially made for more than one column.
As you see here the (alphabetic) order ist horizontally.

If you want to use just one column there is another workaround to have headers.
Like this
 

And the script
Code:
<script type="text/javascript" charset="utf-8">
    $(document).ready(function() { 
        var SubHeading1="Subquestions 1-3";
        var SubHeading2="Subquestions 4-6";
        var SubHeading3="Subquestions 7-8";
        var thisQuestion = $('#question{QID}');
         // Insert sub-headings
        $('.question-item:eq(0)', thisQuestion).before('<li class="inserted-sub-heading"><span class="myHeader">'+SubHeading1+'</span></li>');
        $('.question-item:eq(3)', thisQuestion).before('<li class="inserted-sub-heading"><span class="myHeader">'+SubHeading2+'</span></li>');
        $('.question-item:eq(6)', thisQuestion).before('<li class="inserted-sub-heading"><span class="myHeader">'+SubHeading3+'</span></li>');
    });
</script>


 and css
Code:
<style type="text/css">.myHeader {
    color:maroon;
    font-size:120%;
    background-color:#F8F8FF;
    border:1px solid #ccc;
    padding: 1px 5px;
  }
  .inserted-sub-heading {
    margin-bottom:12px;
  }
</style>

If you want to use a question of type "multiple with comments" you have to exchange .question-item to .checkbox-text-item
Maybe like this:
 

And you remove the not needed text fields with this script
Code:
<script type="text/javascript" charset="utf-8">
    $(document).ready(function() { 
      $('.checkbox-text-item:eq(0) .comment-item', thisQuestion).remove();      
      $('.checkbox-text-item:eq(1) .comment-item', thisQuestion).remove();      
      $('.checkbox-text-item:eq(3) .comment-item', thisQuestion).remove();      
      $('.checkbox-text-item:eq(4) .comment-item', thisQuestion).remove();      
      $('.checkbox-text-item:eq(6) .comment-item', thisQuestion).remove();      
    });
</script>


Adapt to your needs.

Joffm
 

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 1 year 9 months ago by Joffm.

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose