Have an idea?

Visit Sawtooth Software Feedback to share your ideas on how we can improve our products.

Muliple languages in multi-select dropdown question

I have a multi-select drop down question. Everything works as it should, but our QC people realized that the text showing up in the drop down is in English only.
Working Code
<script>
$(document).ready(function(){
    // Settings
    var searchable = false;
    var closeDropdownOnSelection = true;
    var hideInputElements = false;
    
    var closedDropdownSymbol = '▼';
    var openedDropdownSymbol = '▲';
    var placeholderDropdownText = 'Type to search';
    var noResultsDropdownText = 'No results found';
    var closedDropdownText = function(selectedItems) {
        // Good preset for checkboxes: shows "X options selected" if an item is selected, or "Select options."
        var numberOfSelectedItems = selectedItems.length;
        switch (numberOfSelectedItems) {
            case 0:
                return 'Select Route(s)';
                break;
            case 1:
                return '1 option selected';
                break;
            default:
                return numberOfSelectedItems + ' options selected';
                break;
        }
    }


I am interested in the return whosn on lines 17 and 20.  We have translated text for those, bu tI'm not sure how to incorporate it.  I have tried the following

                return '<div class="language" data-language="1">
                        Select Route(s)
                        </div>
                        <div class="language" data-language="2">
                        Something other than English
                        </div>';
                break;


but when I test it, the question does not appear.  We need to replicate this for a total of eight (8) langauges.  I'm pretty sure it's a simple oversight on my part cause I no know how to code.

Can you please help
asked Aug 3 by Nwiggin Bronze (1,825 points)

1 Answer

0 votes
Assuming your Custom Dropdown will continue to stay non-searchable, we should be able to fix this with two changes.

First, the multi-line string you've created is not valid JavaScript.  We need to either remove the new lines in the string, replace the apostrophes with backticks (`), or concatenate multiple strings together like this:

return 'abc' +
'def' +
'ghi';


Second, seek out this line in the code:

$('#[% QuestionName() %]_div .customdropdown_nonsearchablediv').text(text);


and replace it with this:

$('#[% QuestionName() %]_div .customdropdown_nonsearchablediv').html(text);
answered Aug 3 by Zachary Platinum Sawtooth Software, Inc. (209,075 points)
Zach,

Thanks! This did it.
...