In 5.x, this script and style sheet in the source of an array-numbers-texts question will insert check-boxes in the last row. These check-boxes will be exclusive of all inputs in their columns:
Code:
<script type="text/javascript" data-author="Tony Partner">
$(document).on('ready pjax:scriptcomplete',function(){
// Identify this question
var qID = '{QID}';
var thisQuestion = $('#question'+qID);
var exclusiveRow = $('tr[id^="javatbd"]:last', thisQuestion);
var normalRows = $('tr[id^="javatbd"]', thisQuestion).not(exclusiveRow);
// The value to be loaded in the exclusive inputs
var exclusiveVal = '1';
// Index the array columns
$('table.subquestion-list tr', thisQuestion).each(function(i) {
$('> *', this).each(function(i) {
$(this).attr('data-index', i);
});
});
// Hide the last-row inputs
$(':text', exclusiveRow).hide();
// Insert the check-boxes
$('.answer-item', exclusiveRow).each(function(i) {
var thisIndex = $(this).attr('data-index');
$(this).addClass('with-inserted-checkbox').append('<span class="checkbox-item">\
<input type="checkbox" name="insertedInput'+thisIndex+'" id="insertedInput'+thisIndex+'" value="" />\
<label for="insertedInput'+thisIndex+'" class="checkbox-label control-label"></label>\
</span>');
});
// A listener on the normal text inputs
$('input[type="text"]', normalRows).on('change keyup', function (event) {
if($.trim($(this).val()) != '') {
var thisCell = $(this).closest('.answer-item');
var thisIndex = $(thisCell).attr('data-index');
$('.answer-item[data-index="'+thisIndex+'"] input[type="hidden"]', exclusiveRow).val('');
$('.answer-item[data-index="'+thisIndex+'"] :text', exclusiveRow).val('').trigger('keyup');
$('.answer-item[data-index="'+thisIndex+'"] :checkbox', exclusiveRow).prop('checked', false);
}
});
// Listener on the exclusive checkboxes
$(':checkbox', exclusiveRow).on('change', function (event) {
if($(this).is(':checked')) {
var thisCell = $(this).closest('.answer-item');
var thisIndex = $(thisCell).attr('data-index');
$('.answer-item[data-index="'+thisIndex+'"] input[type="hidden"]', normalRows).val('');
$('.answer-item[data-index="'+thisIndex+'"] :text', normalRows).val('').trigger('keyup');
$(':text', thisCell).val(exclusiveVal).trigger('keyup');
}
else {
$(':text', thisCell).val('').trigger('keyup');
}
});
});
</script>