Please help us help you and fill where relevant: Your LimeSurvey version: 5.2.13 Own server or LimeSurvey hosting: LimeSurvey Survey theme/template: fruity
==================
Hi everyone,
I'm wondering if I can make an array table with one cell that allows participants to answer via checkbox and include some text. Or perhaps the only way to do this is to include another column so participants can add text to that column instead?
I'm attaching the test LSS file as well as a mock up.
Thank you all!
This script will move the text inputs from a following multiple-short-text question into the second column of the first two rows. It also applies a couple of basic listeners to the inputs.
Code:
<script type="text/javascript" data-author="Tony Partner">
$(document).on('ready pjax:scriptcomplete',function(){
var thisQuestion = $('#question{QID}');
var nextQuestion = $(thisQuestion).nextAll('.multiple-short-txt:eq(0)');
// Hide the next question
$(nextQuestion).hide();
// Move the text inputs
// First row, second column
$('tr.answers-list:eq(0) .answer-item:eq(1)', thisQuestion).addClass('text-item').append($('.answer-item:eq(0) input:text', nextQuestion));
// Second row, second column
$('tr.answers-list:eq(1) .answer-item:eq(1)', thisQuestion).addClass('text-item').append($('.answer-item:eq(1) input:text', nextQuestion));
// Listeners
$('.answer-item input:text', thisQuestion).on('keyup', function(e) {
if($.trim($(this).val()) != '') {
$(this).closest('.answer-item').find(':radio').trigger('click');
}
});
$('.answer-item input:radio', thisQuestion).on('click', function(e) {
if($(this).closest('.answer-item').find(':text').length == 0) {
$(this).closest('tr').find(':text').val('').trigger('keyup');
}
});
// Cleanup styles
$('.answer-item input:text', thisQuestion).css({
'margin-left': '-10px'
});
});
</script>
Thank you, tpartner! I forgot to include a detail that I wanted to include some text in between the checkbox and text input to make the textbox make sense. I tried to play around with a code like this that you had posted in a different thread but am having trouble with it. Thank you, if you may have a chance to help with this!
var insertedText = "Inserted text";
$('table.subquestion-list thead tr:last td:first', thisQuestion).addClass('inserted-header').append(insertedText);