Hi,you already found this solution, didn't you?
forums.limesurvey.org/forum/can-i-do-thi...ment-fields?start=15
I adapted the script by removing everything related to the array rows, put the button into the question text and got:
First the button (a simple bootstrap button):
Code:
<button class="btn btn-default btn-xs" data-backdrop="static" data-keyboard="false" data-bs-target="#comments-{QID}-1" data-bs-toggle="modal" type="button">Click to add a comment</button>
and the script:
Code:
<script type="text/javascript" charset="utf-8">
$(document).on('ready pjax:scriptcomplete',function(){
// Identify the questions
var qArrayID = {QID};
var qArray = $('#question'+qArrayID);
var arrayLength = $('tr.answers-list', qArray).length;
var qComments = qArray.nextAll('.text-long:lt('+arrayLength+')');
// Add some classes
qArray.addClass('array-with-comments-question');
$(qComments).each(function(i) {
$(this).addClass('comments-question index-'+i).css({
'position': 'absolute',
'left': '-9999em'
});
});
// Handle comments
$(qComments).each(function(i) {
// Create modals
$('body').append('<div class="modal comments-modal" id="comments-'+qArrayID+'-'+(i+1)+'" tabindex="-1" role="dialog">\
<div class="modal-dialog" role="document">\
<div class="modal-content">\
<div class="modal-header">\
<h5 class="modal-title">'+$('.ls-label-question', this).html()+'</h5>\
</div>\
<div class="modal-body">\
</div>\
<div class="modal-footer">\
<button type="button" class="btn btn-primary" data-bs-dismiss="modal">Okay</button>\
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Clear</button>\
</div>\
</div>\
</div>\
</div>');
// Move textareas into modals
$('#comments-'+qArrayID+'-'+(i+1)+' .modal-body').append($('textarea', this));
// Modal button events
$('#comments-'+qArrayID+'-'+(i+1)+' .modal-footer .btn-secondary').on('click', function(e) {
$('#comments-'+qArrayID+'-'+(i+1)+' textarea').val('');
});
});
// Interrupt the Next/Submit function (to put comments back in the form)
$('#limesurvey').submit(function(e) {
$('.comments-modal[id^="comments-'+qArrayID+'-"]').each(function(i) {
var qID = $('textarea:eq(0)', this).attr('id').split('X')[2];
$('#question'+qID+' .answer-item:eq(0)').append($('textarea:eq(0)', this));
});
});
});
</script>
Joffm
The script can be simplified more ( there is only one comment); so no need to use the each-function.
But I am not familiar at all with javascript. It's only Amateurishness.