Welcome to the LimeSurvey Community Forum

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

Array with first text and then with radiolist

  • RomTav
  • RomTav's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 years 4 months ago - 2 years 4 months ago #223198 by RomTav
Please help us help you and fill where relevant:
Your LimeSurvey version: Version 5.2.5
Own server or LimeSurvey hosting: LimeSurvey hosting
Theme: fruity

==================

Hello, 
Is it possible to create an array starting with 3 text columns and finishing with 5-choice radiolists? 
I adapted a .lsg code doing the other way round (starting with radiolist) and managed to add a second text column:
 

I could not find a way to reorder the array for it to start with the text field. I tried to use the function ".prepend()" instead of ".append()" but the subquestions' titles were then placed on the middle of the array:
 

Do you know how I could either hide the subquestions column or reorder the array for it to start with text fields? 
You can find attached the .lsg code for "test1.png" :  

File Attachment:

File Name: fivebutton...Text.lsg
File Size:18 KB


Thanks in advance !

 
Last edit: 2 years 4 months ago by RomTav.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 4 months ago - 2 years 4 months ago #223200 by Joffm
Please, always provide lss exports of the relevant questions.
lsq and lsg exports are language sensitive. (You can't import them into a survey with different base language)

An alternative is to use a drop-down instead of radio buttons.
Like this (additionally with different column widths)
 

 

File Attachment:

File Name: limesurvey...7559.lss
File Size:26 KB


Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 2 years 4 months ago by Joffm.
The following user(s) said Thank You: RomTav

Please Log in to join the conversation.

  • RomTav
  • RomTav's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 years 3 months ago #223304 by RomTav
Thank you for your answer. Indeed, a drop-down menu seems appropriate, and it works perfectly ! 

As we need to create an online survey that corresponds as much as we can to the format used on paper (not editable), do you know if keeping radiolist instead of dropdown menu could be feasible? 

If not, the solution you proposed is a good alternative and we could go on with it !

Best regards, 

Romane 
 

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Online
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 3 months ago #223308 by tpartner
Replied by tpartner on topic Array with first text and then with radiolist
We have no clue about what you have tried.

As Joffm suggests, attach a small sample survey (.lss file) containing only the relevant questions.

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.

  • RomTav
  • RomTav's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 years 3 months ago #223315 by RomTav
Thank you for your time and sorry if I was not clear enough. 
You can find attached the file .lss with the three tests undertaken, I hope this could help.

The desire format is the following: 
 

The alternative given by Joffm can answer our need as it gathered all the information required and in the good order. 
To be consistent with the format from the paper questionnaire (as in the picture just above), I was wondering if it is possible to create a table with first 3 columns of texts and then 5 columns of radio buttons. 

Thank you in advance, 

Romane
 

Please Log in to join the conversation.

  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 3 months ago - 2 years 3 months ago #223316 by holch

As we need to create an online survey that corresponds as much as we can to the format used on paper (not editable),

Probably the most common mistake ever made when it comes to digitalizing questionnaires.

I understand why some people are concerned of changing the way of a questionnaire, but you are already changing it a bit by moving it online, you might as well go all the way and make a clean cut. At least that is my philosophy. Because if you don't do it now, you will never do it and always get stuck with a suboptimal online questionnaire.

And then there is the issue of mobile, where these approaches won't work anyway and you will have to adapt. So now you have those that fill the questionnaire on a big screen the "traditional" way (more or less, because it is already different anyway) and then you have those that fill it on a mobile device (and their number is growing) and they will have a completely different experience.

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

Last edit: 2 years 3 months ago by holch.

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Online
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 3 months ago #223422 by tpartner
Replied by tpartner on topic Array with first text and then with radiolist

I could not find a way to reorder the array for it to start with the text field. I tried to use the function ".prepend()" instead of ".append()" but the subquestions' titles were then placed on the middle of the array:


You cannot simply use prepend() because the first cells in each row must remain in place. You will need to use after().

Code:
<script type="text/javascript" data-author="Tony Partner">
 
  $(document).on('ready pjax:scriptcomplete',function(){
 
    // Identify the questions
    var qArrayID = {QID};
    var qArray = $('#question'+qArrayID);
    var qMultiText = qArray.nextAll('.multiple-short-txt:eq(0)');
    var qMultiTextBis = qMultiText.nextAll('.multiple-short-txt:eq(0)');
 
    // Hide the multi-short-text question
    $(qMultiText).hide();
    $(qMultiTextBis).hide();
 
    // Remove the core column widths
    $('table.questions-list col:not(.col-answers)', qArray).css('width', 'auto');
 
    // Insert the header cells
    $('table.questions-list thead td:eq(0)', qArray).after('<th class="answer-text inserted-column-label" /></th><th class="answer-text-bis inserted-column-label-bis" /></th>');
    $('.inserted-column-label, .inserted-column-label-bis', qArray).css('width','30%');
 
    // Insert the answer row cells
    $('tr.answers-list', qArray).each(function(i) {
      $('.answertext', this).after('<td class="answer-item text-item"></td><td class="answer-item text-item-bis"></td>');
    });
 
    // Load the column label for the text inputs
    $('.inserted-column-label:eq(0)', qArray).text($('.ls-label-question', qMultiText).text());
    $('.inserted-column-label-bis:eq(0)', qArray).text($('.ls-label-question', qMultiTextBis).text());
 
 
    // Loop through the multi-short-text sub-questions
    $('li.answer-item', qMultiText).each(function(i) {
      // Move the text inputs into the array
      $('input[type="text"]', this).appendTo($('tr.answers-list:eq('+i+') .text-item', qArray));
    });
 
    $('li.answer-item', qMultiTextBis).each(function(i) {
      // Move the text inputs into the array
      $('input[type="text"]', this).appendTo($('tr.answers-list:eq('+i+') .text-item-bis', qArray));
    });
 
 
  });
</script>



Sample survey attached: 

File Attachment:

File Name: limesurvey...6779.lss
File Size:41 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: eniisula

Please Log in to join the conversation.

  • RomTav
  • RomTav's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 years 3 months ago #223430 by RomTav
Thanks a lot for your time and the solution, it is exactly what we need !

Please Log in to join the conversation.

More
2 years 1 month ago - 2 years 1 month ago #226015 by mt9999
Hi tpartner,

I'm trying to do something similar but am having trouble adapting this code for my question as I have one column for text input and 4 rows of multiple choice responses (participants can choose more than one of these options). Would you be able to help with this? 

I'm also trying to enter this into a dual scale array as I'd like one side to have a header though I'm assuming no easy way to remove the top header on the left side of the dual array scale (as seen in attached image). I'm still trying to find a workaround to allow participants to enter a checkbox and text if they choose Other as well.

Thank you for any assistance!

EDIT I'm using version 5.2.13, fruity theme and hosted on LimeSurvey
 
Last edit: 2 years 1 month ago by mt9999. Reason: Forgot to include LimeSurvey version

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 1 month ago #226020 by Joffm
Hi,
do it the other way.
An array(text) where you insert checkboxes.
Like this
 
Code:
<script type="text/javascript" charset="utf-8">
 
  $(document).on('ready pjax:scriptcomplete',function(){
 
    // Identify this question
    var thisQuestion = $('#question{QID}');
 
    // Column-specific classes
    $('tr.subquestion-list', thisQuestion).each(function(i) {
      $('th, td', this).each(function(i) {
        $(this).addClass('column-'+i);
      });
    });
 
    // Insert checkboxes
    $('.answer-item.column-1, .answer-item.column-2, .answer-item.column-3, .answer-item.column-4, .answer-item.column-7, .answer-item.column-8', thisQuestion).addClass('custom-checkbox-item');
    $('.custom-checkbox-item', thisQuestion).each(function(i) {
      var thisID = $('input:text:eq(0)', this).attr('id');
      $('label', this).before('<input class="" id="'+thisID+'" value="Y" type="checkbox" name="'+thisID.replace(/answer/, '')+'" />');
      if($('input:text:eq(0)', this).val() == 'Y') {
        $('input:checkbox:eq(0)', this).prop('checked', true);
      }
      $(this).removeClass('text-item').addClass('checkbox-item');
      $('input:text:eq(0)', this).remove();
    });
 
    // Identify exclusive items
    $('.answer-item.column-1, .answer-item.column-2, .answer-item.column-3, .answer-item.column-4, .answer-item.column-5, .answer-item.column-6', thisQuestion).addClass('non-exclusive-item');
    $('.answer-item.column-7, .answer-item.column-8', thisQuestion).addClass('exclusive-item');
 
    // Listeners for exclusive items
    $('.non-exclusive-item input:checkbox', thisQuestion).on('change', function(e) {
      if($(this).is(':checked')) {
        $(this).closest('tr.subquestion-list').find('.exclusive-item input:checkbox').prop('checked', false);
      }
    });
    $('.non-exclusive-item input:text', thisQuestion).on('keyup change', function(e) {
      if($.trim($(this).val()) != '') {
        $(this).closest('tr.subquestion-list').find('.exclusive-item input:checkbox').prop('checked', false);
      }
    });
    $('.exclusive-item input:checkbox', thisQuestion).on('change', function(e) {
      if($(this).is(':checked')) {
        var thisItem = $(this).closest('.answer-item');
        $(this).closest('tr.subquestion-list').find('.answer-item').not(thisItem).find('input:checkbox').prop('checked', false);
        $(this).closest('tr.subquestion-list').find('input:text').val('');
      }
    });
    });
</script>

And the different column width:
Code:
<script type="text/javascript" charset="utf-8">
  $(document).on('ready pjax:scriptcomplete',function(){
    var thisQuestion = $('#question{QID}');
    // Add a question class
    thisQuestion.addClass('custom-array');
    // Column-specific classes
    $('table.subquestion-list tr', thisQuestion).each(function(i) {
      $('th, td', this).each(function(i) {
        $(this).addClass('column-'+i);
      });
    });
  });
</script>
Code:
<style type="text/css">.custom-array table.subquestion-list col {width: auto !important;}.custom-array table.subquestion-list thead .column-0 { width: 16%; }
.custom-array table.subquestion-list thead .column-1 { width: 7%; }
.custom-array table.subquestion-list thead .column-2 { width: 7%; }
.custom-array table.subquestion-list thead .column-3 { width: 7%; }
.custom-array table.subquestion-list thead .column-4 { width: 7%; }
.custom-array table.subquestion-list thead .column-5 { width: 21%; }
.custom-array table.subquestion-list thead .column-6 { width: 21%; }
.custom-array table.subquestion-list thead .column-7 { width: 7%; }
.custom-array table.subquestion-list thead .column-8 { width: 7%; }</style>
Adapt to your needs.

And there are many examples here to have this additional header.

Joffm
 

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

Please Log in to join the conversation.

More
6 months 6 days ago #251377 by Malak_khashoqji
Replied by Malak_khashoqji on topic Array with first text and then with radiolist
I tried to deploy the same script but all i got is a table with checkboxes
what I'm trying to do is as described in the picture
and the value of the checkboxes related to the values of the rows

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 months 5 days ago #251382 by Joffm
Hi, why did yoou switch to this thread, insted of staying in your "old" one?

Okay.
1. I thought you'd like to have one checkbox and two text fields.
But I see only two items on the x-scale

2. I wrote "Adapt the script". You did not.
Didn't you see this line in the script?
Code:
// Insert checkboxes
    $('.answer-item.column-1, .answer-item.column-2, .answer-item.column-3, .answer-item.column-4, .answer-item.column-7, .answer-item.column-8', thisQuestion).addClass('custom-checkbox-item');
Here you see, that in this example (easy to see if you compared with the screenshot) checkboxes are inserted into columns 1,2,3,4,7,8.
Remove what is not needed.

Furthermore I wrote about the "exclusiveness" of checkboxes.
This you see here
Code:
    // Identify exclusive items
    $('.answer-item.column-1, .answer-item.column-2, .answer-item.column-3, .answer-item.column-4, .answer-item.column-5, .answer-item.column-6', thisQuestion).addClass('non-exclusive-item');
    $('.answer-item.column-7, .answer-item.column-8', thisQuestion).addClass('exclusive-item');
 
    // Listeners for exclusive items
till the end.

If you don't want to use it, remove. too.

But please keep the last clisong brackets.

Joffm


 

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

Please Log in to join the conversation.

Lime-years ahead

Online-surveys for every purse and purpose