Welcome to the LimeSurvey Community Forum

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

Dropdown list in Array text with multiple language export?

  • cindy16
  • cindy16's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 8 months ago #204470 by cindy16
Dear all,

I have found a code hier to add Dropdown list in a array text question type. It works great (thanks for that) and we use it in three different languages(english, chinese and russian).

Now when exporting, we need the other two languages to also be in english. Normally is not a problem, but since this is a code, only the options are still in the "original language". Is there a way to automatically translate the Dropdown list option into english when exporting? Please see example below.

Thank you in Advance for your help.

Best Regards,
Cindy
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 8 months ago #204476 by tpartner
You can adjust the script so it records the drop-down option value instead of the label.

Code:
<script type="text/javascript" charset="utf-8">
  $(document).on('ready pjax:scriptcomplete',function(){
    var thisQuestion = $('#question{QID}');
 
    // Insert selects
    $('.answer-item.answer_cell_X002', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\
                          <option value="">Please choose...</option>\
                          <option value="1">Import</option>\
                          <option value="2">Export</option>\
                          <option value="3">Joint Venture</option>\
                          <option value="4">Distributorship</option>\
                          <option value="5">Franchise</option>\
                          <option value="6">Others</option>\
                        </select>');  
    $('.answer-item.answer_cell_X005', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\
                          <option value="">Please choose...</option>\
                          <option value="1">Signed</option>\
                          <option value="2">Planned</option>\
                        </select>');   
    // Listeners
    $('.inserted-select', thisQuestion).on('change', function(i) {
      if($(this).val() != '') {
        $(this).closest('.answer-item').find('input:text').val($('option:selected', this).val()).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());
      $('select.inserted-select', thisCell).val(inputText);
    });
 
    // Clean-up styles
    $('select.inserted-select', thisQuestion).css({
      'max-width': '100%'
    });
    $('.with-select input:text', thisQuestion).css({
      'position': 'absolute',
      'left': '-9999em'
    });
  });
</script>

Sample survey attached:

File Attachment:

File Name: limesurvey...3961.lss
File Size:53 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: cindy16
The topic has been locked.
  • cindy16
  • cindy16's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 8 months ago #204479 by cindy16
Wow! Thank you Tony! It works!
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose