Welcome to the LimeSurvey Community Forum

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

comment box in array numbers (checkbox layout) question

  • mt9999
  • mt9999's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
3 years 1 month ago #227913 by mt9999
Please help us help you and fill where relevant:
Your LimeSurvey version: 5.3.11
Own server or LimeSurvey hosting: Limesurvey
Survey theme/template: Fruity
==================
Hello all, apologies if this has been asked before. I'm having trouble implementing a textbox into the array numbers type of question. 
I would like that participants can choose any number of the options and type their 'other' response if applicable. 
However, I want to make it mandatory they at least choose one option or have an 'other' response. 

I've attached my sample survey.
Thanks all! 

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 1 month ago #227919 by tpartner
Place a multiple-short-text question directly after the array question. The new question should have the same sub-questions as the array.

Place this script and CSS in the source of the array question:

Code:
<script type="text/javascript" data-author="Tony Partner">  
 
  $(document).on('ready pjax:scriptcomplete',function(){
 
    var qID = '{QID}';
    var thisQuestion = $('#question'+qID);
    var textQuestion = thisQuestion.nextAll('.multiple-short-txt:eq(0)');
 
    // Hide the multiple-short-text
    textQuestion.hide();
 
    // Move the text inputs
    $('tr[id^="javatbd"]', thisQuestion).each(function (i) {
      $('td:last', this).addClass('text-item with-inserted-text').append($('li[id^="javatbd"]:eq('+i+') :text', textQuestion));
    });
 
    // A listener on the checkboxes
    $('td.checkbox-item.text-item input[type="text"]', thisQuestion).on('change keyup', function (event) {
      handleText($(this));
    });
 
    function handleText(thisInput) {
 
      var thisCell = $(thisInput).closest('td');
 
      if($.trim($(thisInput).val()) != '') {
        $('input:hidden', thisCell).val('1');
        $('input:checkbox', thisCell).prop('checked', true).trigger('change');
      }
      else {
        $('input:hidden', thisCell).val('');
        $('input:checkbox', thisCell).prop('checked', false).trigger('change');
      }
    }
  });
</script>

Code:
<style type="text/css" data-author="Tony Partner">
 
  .dir-ltr .ls-answers td.checkbox-item.with-inserted-text {
    padding: 4px;
  }
 
  td.with-inserted-text label::before,
  td.with-inserted-text label::after {
    display: none;
  }
 
  @media only screen and (min-width: 768px) {
 
    .dir-ltr .ls-answers td.checkbox-item.with-inserted-text {
      padding: 8px 3px;
    }
 
    .dir-ltr .ls-answers td.with-inserted-text label {
      display: none;
    }
  }
</style>

Sample survey attached: 

File Attachment:

File Name: limesurvey...3(1).lss
File Size:44 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: mt9999

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose