Have an idea?

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

Prefill Ranking Question

Hi,

I would like to use a ranking question with 10 items and a parting ranking for the top5 items. But unlike the standard ranking question in Lighthouse I would like to prefill the answers meaning that a respondent already sees 5 items included in the ranking and is allowed to change the order or exchange the items. I think this reqires a bit more custom code. Can anyone help please?
asked Jul 8, 2021 by FlSa (150 points)
That should be doable, but I have two follow-up questions.  First, what type of ranking question are you using - drag-to-container perhaps?  Second, how are you choosing which of the five items to pre-rank and in what order?
Hi,
thanks for your answer. The 5 pre-selected items would be added as pass-in fields to the individual link. And yes, drag-to-container would be the type of the ranking question.
Hey  Zachary,
thanks again for your help. I have another question about this. At the moment, you can see the pre-filled ranking. Then you can remove individual items and replace them with others. If you remove one, all subsequent ranks move up one position. Would it be possible to prevent this? So that the place where you take an item remains free? Many thanks in advance.
I don't think there's going to be a simple way of doing that with the JavaScript tools used to run the ranking question.  If this is a requirement for your study, you may need to contact our consulting team to go over specifics and get a quote.
Ok, thank you.

1 Answer

+2 votes
 
Best answer
Please try adding this script to your ranking question:

<script>
$(document).on('ssi_ready', function(){
    // Params
    var preranks = [
        [% PreRank1 %],
        [% PreRank2 %],
        [% PreRank3 %],
        [% PreRank4 %],
        [% PreRank5 %]
    ];
    
    // Run
    var rankedArea = $('#[% QuestionName() %]_div .ranked_sort_area');
    if (!rankedArea.children().length) {
        for (var i = 0; i < preranks.length; i++) {
            var button = $('#[% QuestionName() %]_' + preranks[i] + '_button');
            rankedArea.append(button);
            button.find('.rank_number').text(i + 1);
            $('#[% QuestionName() %]_' + preranks[i]).val(i + 1);
        }
    }
})
</script>


Lines 5-9 should be updated so that each line has the name of one of your pass-in fields.
answered Jul 8, 2021 by Zachary Platinum Sawtooth Software, Inc. (202,300 points)
selected Jul 12, 2021 by FlSa
Very nice work Zachary.
Great! Thanks a lot.
...