Luke, due to your somewhat aged LS version, we can do something similar to Jan's solution but will need to pass the sub-question codes and values to page 2 via a couple of hidden short-texts and a hidden boilerplate question. We'll also need to modify the functions slightly to handle the different method of passing data.
1) Add the following variation of the workaround function to your template.js file:
// A function to filter choices in a ranking question
function rankFilter2(q1ID, q2ID) {
// Hide the boilerplate
$('#question'+q1ID+'').hide();
// Find the survey and group IDs
if($( 'input#fieldnames' ).length != 0) {
var fieldNames = $( 'input#fieldnames' ).attr('value');
var tmp = fieldNames.split('X');
var sID = tmp[0];
var gID = tmp[1];
}
// Handle the option codes and text passed from page 1
var triggers = $('#question'+q1ID+' .triggers').text().split(',');
var nonTriggers = $('#question'+q1ID+' .nonTriggers').text().split(',');
$(triggers).each(function(i) {
// Split out the answer code and value
var tmp2 = this.split('|*|');
var ansCode = tmp2[0];
var ansTxt = tmp2[1];
// If option is checked and not in rank choices or output, add it to the rank choices
if($('#question'+q2ID+' select.select option[value="'+ansCode+'"]').length == 0 && $('#question'+q2ID+' .output input[id^="fvalue_"][value="'+ansCode+'"]').length == 0) {
$('<option value="'+ansCode+'">'+ansTxt+'</option>').appendTo('#question'+q2ID+' select.select');
}
});
$(nonTriggers).each(function(i) {
// Split out the answer code and value
var tmp2 = this.split('|*|');
var ansCode = tmp2[0];
var ansTxt = tmp2[1];
// Remove it from the rank choices
$('#question'+q2ID+' select.select option[value="'+ansCode+'"]').remove();
// Remove it from the rank output and reset hidden values
$('#question'+q2ID+' .output input[id^="fvalue_"][value="'+ansCode+'"]').attr('value', '').siblings('input.text').val('').siblings('img').hide();
});
// Clean up empty inputs in the rank output table
$('#question'+q2ID+' .output table tr').each(function(i) {
var nextRow = $(this).next('tr');
if($('input.text', this).val() == '' && $('input.text', nextRow).val() != '') {
$('input.text', this).val($('input.text', nextRow).val());
$('input.text', nextRow).val('');
$('input[id^="fvalue_"]', this).attr('value', $('input[id^="fvalue_"]', nextRow).attr('value'));
$('input[id^="fvalue_"]', nextRow).attr('value', '');
}
});
// Show the scissors for the last populated rank output row
$('#question'+q2ID+' .output table img[id^="cut_"]').hide();
$('#question'+q2ID+' .output table input.text[value!=""]:last').siblings('img[id^="cut_"]').show();
// Hide extra rank output rows
var optNum = $(triggers).length;
$('#question'+q2ID+' .output table tr').hide();
$('#question'+q2ID+' .output table tr:lt('+(optNum+1)+')').show();
maxAnswersFix();
// A listener to work around the built in max-answers function
$('#question'+q2ID+' td.rank').click(function (event) {
maxAnswersFix();
});
// A work around for the built in max-answers function
function maxAnswersFix() {
$('#question'+q2ID+' select.select').attr('disabled', true);
$('#question'+q2ID+' td.output tr:visible').each(function(i) {
if($('input.text', this).val() == '') {
$('#question'+q2ID+' select.select').attr('disabled', false);
}
});
}
}
2) On page 1, create your array question and two short text questions (we'll hide the short texts with JavaScript).
3) Place the following script in the source of one of the questions on page 1. Replace "AA" (line 7) with the
question ID of the array question, "HH1" and "HH2" (line 7) with the question IDs of the short-text questions. The "[1,2,3,4]" param dictates which columns of the array will load "triggers". This script hides the short-text questions and interrupts the next/submit function to load the first short-text with codes and values of subquestions to show in the ranking (triggers) and loads the second short-text with the ones to remove/hide (non-triggers).
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
// Call the function
// Params = Array ID, Hidden Multi-opt ID, "Trigger" columns (in square brackets, separated by comma)
storeTriggers(AA, HH1, HH2, [1,2,3,4]);
function storeTriggers(q1ID, qHidden1ID, qHidden2ID, columns) {
// Add a class to all array cells in "trigger" columns
$(columns).each(function(i) {
var colIndex = (this-1);
$('#question'+q1ID+' table.question tbody').each(function() {
$('td:eq('+colIndex+')', this).addClass('trigger');
});
});
// Hide the hidden questions
$('#question'+qHidden1ID+'').hide();
$('#question'+qHidden2ID+'').hide();
// Find the survey and group IDs
if($('input#fieldnames').length != 0) {
var fieldNames = $('input#fieldnames').attr('value');
var tmp = fieldNames.split('X');
var sID = tmp[0];
var gID = tmp[1];
}
// Interrupt next/submit function
$('form#limesurvey').submit(function(){
var triggers = new Array();
var nonTriggers = new Array();
// Loop through all rows of the array build an array of the "trigger" codes and text
$('#question'+q1ID+' table.question tbody').each(function(i) {
var optTxt = $('th', this).text();
var optTmp = $(this).attr('id').split('X'+gID+'X'+q1ID+'');
var optCode = optTmp[1];
var optString = optCode+'|*|'+optTxt;
if($('.trigger .radio:checked', this).length > 0) {
triggers.push(optString);
}
else {
nonTriggers.push(optString);
}
});
// Populate the hidden questions
$('#question'+qHidden1ID+' input.text').val(triggers);
$('#question'+qHidden2ID+' input.text').val(nonTriggers);
return true;
});
}
});
</script>
4) On page 2, Create a boilerplate question and the ranking question (we'll hide the boilerplate with JavaScript). The ranking question must have identical sub-questions and sub-question codes as the array on page 1.
5) For the boilerplate text, use two {INSERTANS} tags to pipe in the answer from the page 1 short-text questions and wrap them in <span> elements with classes "trigger" and "nonTriggers". So the source of the boilerplate should look something like (with correct IDs, of course):
<span class="triggers">{INSERTANS:11111X22X3}</span><span class="nonTriggers">{INSERTANS:11111X22X4}</span>
6) Place the following script in the source of one of the questions on page 2. Replace "BB" with the ID of the boilerplate question and "RR" with the ID of the ranking question. This calls the rankFilter2 function which hides all choices in the ranking question except those passed from page 1 as "triggers".
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
rankFilter2(BB, RR);
});
</script>