Welcome to the LimeSurvey Community Forum

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

Question themes and adaptable array (text) in LS 3.x

  • PeteReffell
  • PeteReffell's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
5 years 7 months ago #173928 by PeteReffell
Having made use of Denis Chenu's excellent adaptable array plugin in the previous 2.x LimeSurvey, I am struggling to replicate this using Question Themes.
The array set up is quite simple: two columns, the first a drop-down list and the second a default text box.
I have searched around for a solution and the closest I have found is a javascript placed within the question for a repeating Yes/No/Do Not Know drop down applied to each answer. The problem with this is that the selection list I need requires a lot of options and is likely to need to be updated by someone other than me.
I have looked at question themes and I know that this is the way to do it, but I am a bit out to sea with quite how to make the modification. I have installed and looked at Tony Partner's question themes to see if I can do a bit of reverse engineering, but I'm not making much progress.
Can anyone offer me help? The drop down list contains 10+ options.
Thank you for any help you can offer.
I have attached a screen shot of the question as it is using Denis' plugin.
Pete
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 7 months ago #173935 by tpartner
I don't have time today to adapt a question theme but here is a link to a thread describing several ways of doing it with JavaScript - www.limesurvey.org/forum/can-i-do-this-w...dropdown-list#169382

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: PeteReffell
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 7 months ago #173936 by DenisChenu
I don't think you can completely fix it with question theme, since arayTextAdapt use DB (label).

But it can be surely fixed to use twig file

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The following user(s) said Thank You: PeteReffell
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 7 months ago - 5 years 7 months ago #173937 by Joffm
Hi, Pete,
the solution is found here:
www.limesurvey.org/forum/can-i-do-this-w...dropdown-list#169344

I adapted the script to your desire:

Code:
<script type="text/javascript" charset="utf-8">
  $(document).on('ready pjax:scriptcomplete',function(){
    var thisQuestion = $('#question{QID}');
 
    // Insert selects
    $('.answer-item.answer_cell_X001', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\
                          <option value="">Please choose...</option>\
                          <option value="1">Type 1</option>\
                          <option value="2">Type 2</option>\
                          <option value="3">Type 3</option>\
                          <option value="4">Type 4</option>\
                          <option value="5">Type 5</option>\
                          <option value="6">Type 6</option>\
                        </select>'); 
 
    // Listeners
    $('.inserted-select', thisQuestion).on('change', function(i) {
      if($(this).val() != '') {
        $(this).closest('.answer-item').find('input:text').val($.trim($('option:selected', this).text())).trigger('change');
      }
      else {
        $(this).closest('.answer-item').find('input:text').val('').trigger('change');
      }
    });
 
    // Returning to page
    $('.with-select input:text', thisQuestion).each(function(i) {
      var thisCell = $(this).closest('.answer-item');
      var inputText = $.trim($(this).val());
      var selectval = $('select.inserted-select option', thisCell).filter(function () { return $(this).html() == inputText; }).val();
      $('select.inserted-select', thisCell).val(selectval);
    });
 
    // Clean-up styles
    $('select.inserted-select', thisQuestion).css({
      'max-width': '100%'
    });
    $('.with-select input:text', thisQuestion).css({
      'position': 'absolute',
      'left': '-9999em'
    });
  });
</script>

Regards
Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 5 years 7 months ago by Joffm.
The following user(s) said Thank You: PeteReffell
The topic has been locked.
  • PeteReffell
  • PeteReffell's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
5 years 7 months ago #173939 by PeteReffell
Thank you all so much, a great help and a great community to give your time over to people's LS problems.
Pete
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose