Welcome to the LimeSurvey Community Forum

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

Title in a multiple choice question

More
1 year 10 months ago #267099 by Mon2016
Please help us help you and fill where relevant:
Your LimeSurvey version: [see right hand bottom of your LimeSurvey admin screen]  Versión 5.6.42+231024
Own server or LimeSurvey hosting: 
Survey theme/template:
==================
(Write here your question/remark)



Hello to all forum members.

I want to ask you something if it is possible to do it in multiple choice questions.

I have a huge list of 70 codes with different products that you can find in a self-service store but at some point it gets confusing with the quantity so I want to put the title of each department of the store at the top in each answer option. something like I show in the image.






Can it be done in a multiple choice answer question or is there something different to show?


Thanks everyone <3

Please Log in to join the conversation.

More
1 year 10 months ago - 1 year 10 months ago #267101 by Joffm
Hi,
yes you can do this
1. question of type "multiple" where you remove some checkboxes
 
You only enter this script into the source code of the question
Code:
<script charset="utf-8" type="text/javascript">
  $(document).ready(function() {
    $( '#question{QID} .question-item:eq(0)').addClass('hide-pseudo-elements').find('input.checkbox').remove();
    $( '#question{QID} .question-item:eq(7)').addClass('hide-pseudo-elements').find('input.checkbox').remove();
    $( '#question{QID} .question-item:eq(13)').addClass('hide-pseudo-elements').find('input.checkbox').remove();
  });
</script>


You see here (eq(x) the rows where the checkbox is removed (starting with 0)
And some styling
I used a class called .myHeader to shorten the subquestion text
 
Code:
<style type="text/css">.hide-pseudo-elements label::before,
  .hide-pseudo-elements label::after
  {
    display: none;
  }
 
  .hide-pseudo-elements .label-text
  {
    margin-left: -40px;
  }
 
  .myHeader
  {
    color: maroon;
    font-weight: bold;
    background-color: #eeeeee;
    border: 1px solid #cccccc;
    padding: 1px 5px;
    margin-left: -25px;
    display: inline-block;
   min-width: 100%;
}
 
  li.radio-item, li.checkbox-item, li.radio-text-item, li.checkbox-text-item {
    margin-bottom: 0.5em;
  }
 
.checkbox-item label {
  min-width: 100%;
}
</style>


You see with your 70 items it will be a very long and boring list.
But it will get messy if you display in more than one column.
 

Therefore there ist a different solution based on a question "multiple with comments"
Now the items are ordered horizontally
 

This script
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 = 'O';
    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>


And the css
Code:
<style data-author="Tony Partner" type="text/css">li.inserted-header-row {
    float: none;
    clear: both;
    flex: 0 0 100%;
  }
 
  li.inserted-header-row label {
/* Hier wird das Layout der Überschrift; kann man alles nach Gusto ändern */
    padding-left: 15px;
    padding-right: 15px;
    padding-top:0 !important;
    font-weight: bold;
    width: 100%;
    background-color:#e29514;;
    border: 1px solid gray;
    border-radius: 5px;
    font-size: 18px;
    color: #001957;
  }
  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.columns-5 ul.ls-answers li { flex: 0 0 20%; }
 
    .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: center;
    }
 
    .with-inserted-columns ul.ls-answers li input[type="text"] {
      margin-top: 0.7em;
    }
  }
</style>


You see in the code that header rows, other items are marked by a special character in the subquestion code.
Of course you can change this.
var headerRowPrefix = 'O';
var textRowPrefix = 'oth';
 

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 1 year 10 months ago by Joffm.
The following user(s) said Thank You: Mon2016

Please Log in to join the conversation.

More
1 year 10 months ago #267102 by Mon2016
Thank you so much for your great help Joffm

Always being a hero. 

Please Log in to join the conversation.

More
1 year 10 months ago #267103 by Joffm
Another idea to structure this long, long list could be a two-level display
 

 

Now it's your turn.

Send the lss export of this question and we will see.

Joffm

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

Please Log in to join the conversation.

More
6 hours 49 minutes ago #274833 by elissa
I am using the script provided by Joffm to add headers and hide checkboxes in a multiple-choice question, and generally it works well. However, when I limit the number of answers, a problem arises: clicking a header counts toward the total number of selected answers. As a result, respondents are blocked from continuing even though they see only the allowed number of actual options checked.

Is there a way to adapt the script to ignore header clicks when counting answers?

Thank you very much!

Elzbieta Lesinska
LS voluntary Polish translator and supervisor

Please Log in to join the conversation.

More
5 hours 20 minutes ago #274834 by Joffm
My idea:
Rename the codes of the headers, like "H1", H..."
Now you can use the question validation 
count(self)-count(self.sq_H)<5

File Attachment:

File Name: limesurvey...27_J.lss
File Size:33.13 KB


Best regards
Joffm

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

Please Log in to join the conversation.

More
4 hours 13 minutes ago #274835 by elissa
Beautiful. Thank you, Joffm.

Elzbieta Lesinska
LS voluntary Polish translator and supervisor

Please Log in to join the conversation.

More
1 hour 47 minutes ago #274838 by Joffm
Hi,
here's another - better- way to insert headers.
As the headers aren't subquestions thex do not affect the count.
Code:
<script type="text/javascript" charset="utf-8">
    $(document).ready(function() { 
        var SubHeading1="Header 1";
        var SubHeading2="Header 2";
        var SubHeading3="Header 3";
        var thisQuestion = $('#question{QID}');
 
        // Insert sub-headings
        $('.checkbox-item:eq(0)', thisQuestion).before('<li class="inserted-sub-heading"><span class="myHeader">'+SubHeading1+'</span></li>');
        $('.checkbox-item:eq(4)', thisQuestion).before('<li class="inserted-sub-heading"><span class="myHeader">'+SubHeading2+'</span></li>');
        $('.checkbox-item:eq(8)', thisQuestion).before('<li class="inserted-sub-heading"><span class="myHeader">'+SubHeading3+'</span></li>');
    });
</script>
<style type="text/css">.myHeader {
    color: maroon;
    font-weight: bold;
    background-color: #eeeeee;
    border: 1px solid #cccccc;
    padding: 1px 5px;
    margin-left: 25px;
    display: inline-block;
  }  
li.radio-item, li.checkbox-item, li.radio-text-item, li.checkbox-text-item {
    margin-bottom: 0.5em;
}
</style>

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: elissa

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose