Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Array with first column text

  • vzyldd
  • vzyldd's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
1 month 2 weeks ago - 1 month 2 weeks ago #258371 by vzyldd
Array with first column text was created by vzyldd
Please help us help you and fill where relevant:
Your LimeSurvey version: LimeSurvey Community EditionVersion 5.4.15+221212
Own server or LimeSurvey hosting: Own
Survey theme/template: Fruity
==================
I have found a script (Tony Partner) on the forum to insert a text field in the last column of an array type question. The script is working on my version but I need this text field in the first column. I am not sure how to adapt the script. I've tried changing '.answer-item:last-child' in the script to '.answer-item:first-child' but, due to my limited knowledge, it was a total disaster.

Currently the display is as follows:
  

The script used:<script type="text/javascript" data-author="Tony Partner">
$(document).on('ready pjax:scriptcomplete',function(){
 
// Identify the questions
var thisQID = {QID};
var thisQuestion = $('#question'+thisQID);
var textQuestion = thisQuestion.nextAll('.multiple-short-txt:eq(0)');
var textQID = textQuestion.attr('id').replace(/question/, '');
 
// Hide the text question
textQuestion.hide();
 
// Remove all radios from last column
$('.answer-item:last-child', thisQuestion).removeClass('radio-item').addClass('text-item');
$('.answer-item:last-child :radio', thisQuestion).remove();
 
// Move the text inputs
$('tr.answers-list', thisQuestion). each (function(i) {
var thisCode = $(this).attr('id'). split ('X'+thisQID)[1];
$('.answer-item:last-child', this).append($(':text[id$="X'+textQID+thisCode+'"]', textQuestion));
});
});
</script>
Last edit: 1 month 2 weeks ago by vzyldd.

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 month 2 weeks ago #258402 by tpartner
Replied by tpartner on topic Array with first column text
This'll do the trick:

Code:
<script type="text/javascript" data-author="Tony Partner">  
  $(document).on('ready pjax:scriptcomplete',function(){
 
    // Identify the questions
    var thisQID = {QID};
    var thisQuestion = $('#question'+thisQID);    
    var textQuestion = thisQuestion.nextAll('.multiple-short-txt:eq(0)');
    var textQID = textQuestion.attr('id').replace(/question/, '');
 
    // Hide the text question
    textQuestion.hide();
 
    // Remove all radios from first column
    $('.answer-item:nth-child(2)', thisQuestion).removeClass('radio-item').addClass('text-item');
    $('.answer-item:nth-child(2) :radio', thisQuestion).remove();
 
    // Move the text inputs
    $('tr.answers-list', thisQuestion).each(function(i) {
      var thisCode = $(this).attr('id').split('X'+thisQID)[1];
      $('.answer-item:nth-child(2)', this).append($(':text[id$="X'+textQID+thisCode+'"]', textQuestion));
    });
  });
</script>

 

Sample survey: 

File Attachment:

File Name: limesurvey...8551.lss
File Size:30 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: vzyldd

Please Log in to join the conversation.

  • vzyldd
  • vzyldd's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
1 month 2 weeks ago #258404 by vzyldd
Replied by vzyldd on topic Array with first column text
Big thank you Tony. You are a legend.

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 month 2 weeks ago #258405 by tpartner
Replied by tpartner on topic Array with first column text
Here is a version that will toggle the inputs when a radio is clicked or some text is entered:

Code:
<script type="text/javascript" data-author="Tony Partner">  
  $(document).on('ready pjax:scriptcomplete',function(){
 
        // Identify the questions
        var thisQID = {QID};
        var thisQuestion = $('#question'+thisQID);    
        var textQuestion = thisQuestion.nextAll('.multiple-short-txt:eq(0)');
        var textQID = textQuestion.attr('id').replace(/question/, '');
 
        // Hide the text question
        textQuestion.hide();
 
        // Remove all radios from first column
        $('.answer-item:nth-child(2)', thisQuestion).removeClass('radio-item').addClass('text-item');
        $('.answer-item:nth-child(2) :radio', thisQuestion).remove();
 
        // Move the text inputs
        $('tr.answers-list', thisQuestion).each(function(i) {
            var thisCode = $(this).attr('id').split('X'+thisQID)[1];
            $('.answer-item:nth-child(2)', this).append($(':text[id$="X'+textQID+thisCode+'"]', textQuestion));
        });
 
        // Listener on the radios
        $('.radio-item :radio', thisQuestion).on('click', function(e) {
            $(this).closest('tr').find(':text').val('').trigger('keyup');
        });
 
        // Listener on the text inputs
        $('.text-item :text', thisQuestion).on('keyup change', function(e) {
            if($.trim($(this).val()) != '') {
                var thisRadio = $(this).closest('tr').find(':radio:first');
                $(thisRadio).prop('checked', false);
                checkconditions('', $(thisRadio).attr('name'), 'radio');
            }
        });
 
    });
</script>

Sample survey:  

File Attachment:

File Name: limesurvey...5511.lss
File Size:31 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

  • vzyldd
  • vzyldd's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
1 month 2 weeks ago #258414 by vzyldd
Replied by vzyldd on topic Array with first column text
Exactly what I needed. Works perfectly. Thank you Tony.

Please Log in to join the conversation.

Lime-years ahead

Online-surveys for every purse and purpose