Welcome to the LimeSurvey Community Forum

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

Array with radiolist and text field

  • mcovents
  • mcovents's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
2 years 10 months ago #216706 by mcovents
Array with radiolist and text field was created by mcovents
Hello,
Is it possible to have array type of survey questions (see a non-working printscreen below) in which one can select an option in the first three columns (Ja - Ja, mits ... - Nee, omdat ...) and give a further explanation to the selected option in the last column.
In my survey I have three groups of questions of this type.
For the moment I’m using “lists with comments”, however an array type would make the questionnaire more surveyable.
Has anyone an working example?
I’m using limesurvey 3.17
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 10 months ago #216713 by Joffm
Replied by Joffm on topic Array with radiolist and text field
Hi,

see a non-working printscreen below


In which way does your question not work?

Here a working example.
After your array create a question of type "multiple short text" with the same number of subquestion as your array.

Enter this javascript into the source code of the array question.
Code:
<script type="text/javascript" charset="utf-8">
 
    $(document).on('ready pjax:scriptcomplete',function(){
 
        // Identify the questions
        var qArrayID = {QID};
        var qArray = $('#question'+qArrayID);
//        var arrayLength = $('tr.answers-list', qArray).length;
        var qMultiText = qArray.nextAll('.multiple-short-txt:eq(0)');
 
 
      // Hide the multi-short-text question
        $(qMultiText).hide();
 
        var tableWidth = $('table.questions-list:eq(0)', qArray).width();
        var answerWidth = $('col.ls-col-odd:eq(0)', qArray).width();
        var answerWidthPercent = (answerWidth/tableWidth)*100;
        var answersLength = $('col.ls-col-odd, col.ls-col-even', qArray).length;
        var answerWidthPercent2 = (answerWidthPercent*answersLength)/(answersLength+1)
        $('table.questions-list col', qArray).removeAttr('width');
 
 
$('table.questions-list col:not(.col-answers)', qArray).css('width', 'auto');
 
 
      $('table.questions-list thead tr', qArray).append('<th class="answer-text inserted-column-label" /></th>');
      $('table.questions-list thead tr th.answer-text.inserted-column-label', qArray).css('width','30%');
 
        $('tr.answers-list', qArray).each(function(i) {
            $(this).append('<td class="answer-item text-item">\
                            </td>\
                            ');
        });
 
        // Load the column label for the text inputs
        $('.inserted-column-label:eq(0)', qArray).text($('.ls-label-question', qMultiText).text());
        $('.text-item', qArray).append('<label class="ls-label-xs-visibility">'+$('.ls-label-question', qMultiText).text()+'</label>');
 
        // 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));
        });
 
    });
</script>



 

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 10 months ago #216714 by tpartner
Replied by tpartner on topic Array with radiolist and text field
Here is a simplified version...

1) Add one extra answer to the array with the label you would like for the text column (we will remove the radios from that column via JavaScript)

2) Add a following multiple-short-text question using the same sub-question codes as the array.

3) Insert this script into the array question text:
Code:
<script type="text/javascript" data-author="Tony Partner">  
  $(document).on('ready pjax:scriptcomplete',function(){
 
    // Identify the questions
    var thisQID = {QID};
    var thisQuestion = $('#question'+thisQID);    
    var textQuestion = thisQuestion.nextAll('.multiple-short-txt:eq(0)');
    var textQID = textQuestion.attr('id').replace(/question/, '');
 
    // Hide the text question
    textQuestion.hide();
 
    // Remove all radios from last column
    $('.answer-item:last-child', thisQuestion).removeClass('radio-item').addClass('text-item');
    $('.answer-item:last-child :radio', thisQuestion).remove();
 
    // Move the text inputs
    $('tr.answers-list', thisQuestion).each(function(i) {
      var thisCode = $(this).attr('id').split('X'+thisQID)[1];
      $('.answer-item:last-child', this).append($(':text[id$="X'+textQID+thisCode+'"]', textQuestion));
    });
  });
</script>

Sample survey attached:

File Attachment:

File Name: limesurvey...6(1).lss
File Size:27 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 10 months ago #216715 by Joffm
Replied by Joffm on topic Array with radiolist and text field
I suppose you tried one of the scripts here in the forum.
I think most of them insert an "other" option.
And an array is single punch. So either you select an option or you enter something into the text field.

Therefore  in this script the listeners on radios and text boxes are removed.

Just to explain it.

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • mcovents
  • mcovents's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
2 years 10 months ago #216722 by mcovents
Replied by mcovents on topic Array with radiolist and text field
Thank you both for the prompt reply!However, when I tried the first Javascript (Joffm) and “forgot” to complete one of the questions (like many of our respondents do) the nice layout disappeared and I could not complete the array part of the question any more (see first screenshot).When I tried the second Javascript (tpartner), this works well for 1 array question, however I have three array questions of this type each in his own group and in the second and third array question both parts are separated again (see second screen).=11.0ptAny suggestion?
Best regards,
Marc.
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 10 months ago #216723 by Joffm
Replied by Joffm on topic Array with radiolist and text field
To avoid any guessing, please send your survey (these questions) as lss export.

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • mcovents
  • mcovents's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
2 years 10 months ago #216726 by mcovents
Replied by mcovents on topic Array with radiolist and text field
Please find lss in attach
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 10 months ago #216733 by Joffm
Replied by Joffm on topic Array with radiolist and text field
Sorry,
I could not reproduce any of your problems (3.25.16)
And I inserted Tony's script into three groups - no issue.

Joffm
 

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 10 months ago #216734 by tpartner
Replied by tpartner on topic Array with radiolist and text field
Make sure you have AJAX disabled in the theme options (if available).

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • mcovents
  • mcovents's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
2 years 10 months ago #216735 by mcovents
Replied by mcovents on topic Array with radiolist and text field
Yes, disabling AJAX solves the issue.
Thanks for the suggestion and for testing our survey sample!!!
Marc.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose