Welcome to the LimeSurvey Community Forum

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

Checkbox and text input within one cell in array

  • mt9999
  • mt9999's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
3 years 3 months ago #225999 by mt9999
Please help us help you and fill where relevant:
Your LimeSurvey version: 5.2.13
Own server or LimeSurvey hosting: LimeSurvey
Survey theme/template: fruity
==================
Hi everyone, 
I'm wondering if I can make an array table with one cell that allows participants to answer via checkbox and include some text. Or perhaps the only way to do this is to include another column so participants can add text to that column instead? 
I'm attaching the test LSS file as well as a mock up.
Thank you all! 

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 3 months ago #226029 by tpartner
This script will move the text inputs from a following multiple-short-text question into the second column of the first two rows. It also applies a couple of basic listeners to the inputs.

Code:
<script type="text/javascript" data-author="Tony Partner">  
  $(document).on('ready pjax:scriptcomplete',function(){
 
    var thisQuestion = $('#question{QID}');
    var nextQuestion = $(thisQuestion).nextAll('.multiple-short-txt:eq(0)');
 
    // Hide the next question
    $(nextQuestion).hide();
 
    // Move the text inputs
    // First row, second column
    $('tr.answers-list:eq(0) .answer-item:eq(1)', thisQuestion).addClass('text-item').append($('.answer-item:eq(0) input:text', nextQuestion));
    // Second row, second column
    $('tr.answers-list:eq(1) .answer-item:eq(1)', thisQuestion).addClass('text-item').append($('.answer-item:eq(1) input:text', nextQuestion));
 
    // Listeners
    $('.answer-item input:text', thisQuestion).on('keyup', function(e) {
      if($.trim($(this).val()) != '') {
        $(this).closest('.answer-item').find(':radio').trigger('click');
      }
    });
    $('.answer-item input:radio', thisQuestion).on('click', function(e) {
      if($(this).closest('.answer-item').find(':text').length == 0) {
        $(this).closest('tr').find(':text').val('').trigger('keyup');
      }
    });
 
    // Cleanup styles
    $('.answer-item input:text', thisQuestion).css({
      'margin-left': '-10px'
    });
 
  });
</script>

 

Sample survey attached: 

File Attachment:

File Name: limesurvey...6(3).lss
File Size:35 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: LISHANGQI, mt9999

Please Log in to join the conversation.

  • mt9999
  • mt9999's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
3 years 3 months ago #226071 by mt9999
Thank you, tpartner! I forgot to include a detail that I wanted to include some text in between the checkbox and text input to make the textbox make sense. I tried to play around with a code like this that you had posted in a different thread but am having trouble with it. Thank you, if you may have a chance to help with this!


var insertedText = "Inserted text";
$('table.subquestion-list thead tr:last td:first', thisQuestion).addClass('inserted-header').append(insertedText);

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose