Welcome to the LimeSurvey Community Forum

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

Example Row in Text Array

  • jess29
  • jess29's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
8 years 8 months ago - 8 years 8 months ago #132673 by jess29
Example Row in Text Array was created by jess29
Hello,
I have a text array question. I'd like to have the first row be a sample entry. Heading examples "time of day, location, amount, etc". I want to add a row that says something like "11:45 am, Work, 15oz". Does this make sense? Is this possible?
Last edit: 8 years 8 months ago by jess29.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 8 months ago #132679 by tpartner
Replied by tpartner on topic Example Row in Text Array
Do you mind if those example values are recorded in the data? In other words, can we use an existing row in the array and populate it with the examples or do you need a new completely fake row?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • jess29
  • jess29's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
8 years 8 months ago #132681 by jess29
Replied by jess29 on topic Example Row in Text Array
Nope, that will work as long as it's just one row. We can just note that it's in the data and make sure we remove before any analyses.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 8 months ago - 8 years 8 months ago #132684 by tpartner
Replied by tpartner on topic Example Row in Text Array
Actually, thinking about it a little more, it's just as easy to insert a fake row.

Add this script to the question source ( I think the comments adequately explain what's happening):

Code:
<script type="text/javascript" charset="utf-8">    
  $(document).ready(function(){
 
    // The example text strings
    var column1Label = 'Examples';
    var column1Example = '11:45 am';   
    var column2Example = 'Work';   
    var column3Example = '15oz';   
 
    // Identify the question
    var thisQuestion = $('#question{QID}');
 
    // Create a fake row
    var newRow = $('tr.subquestion-list:eq(0)', thisQuestion).clone();
    $(newRow).addClass('inserted-row');
    $('input[type="text"]', newRow).removeAttr('id').removeAttr('name');
    $('input[type="hidden"]', newRow).remove();
 
    // Insert the example text strings
    $('.answertext', newRow).text(column1Label);
    $('input[type="text"]:eq(0)', newRow).val(column1Example);
    $('input[type="text"]:eq(1)', newRow).val(column2Example);
    $('input[type="text"]:eq(2)', newRow).val(column3Example);
 
    // Disable the fake row inputs
    $('input[type="text"]', newRow).prop('readonly', true);
 
    // Insert the fake row
    $('table.questions-list tbody:eq(0)', thisQuestion).prepend(newRow);
 
    // Fix up the row classes
    var rowClass = 1;
    $('table.subquestions-list tbody tr', thisQuestion).each(function(i) {
      if($(this).hasClass('sub-header-row')) {
        rowClass = 1
      }
      else {
        rowClass++;
        $(this).removeClass('array1 array2')
        if(rowClass % 2 == 0) {
          $(this).addClass('array2');
        }
        else {
          $(this).addClass('array1');
        }
      }
    });  
 
    });
</script>



Sample survey attached:

File Attachment:

File Name: limesurvey...-7-8.lss
File Size:18 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 8 years 8 months ago by tpartner.
The topic has been locked.
  • jess29
  • jess29's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
8 years 8 months ago - 8 years 8 months ago #132685 by jess29
Replied by jess29 on topic Example Row in Text Array
That looks fantastic! But it's not working... I know I'll need to edit a few things for mine as it has a couple extra columns but I started by opening your sample and when I run the survey, I don't see the example row. Am I doing something wrong...?

I'm running version 1.92+ if that matters.

Also just realized I got this error multiple times at the top of my screen:
Notice: Undefined index: help in /opt/virtualhosts/surveys.vtti.vt.edu/htdocs/admin/import_functions.php on line 1317
Last edit: 8 years 8 months ago by jess29.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 8 months ago #132686 by tpartner
Replied by tpartner on topic Example Row in Text Array
Hmm...1.92 might matter...can you activate that test survey and give us a link so I can see the source?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 8 months ago #132687 by tpartner
Replied by tpartner on topic Example Row in Text Array
Never mind, I got it.

Use this code for 1.92:

Code:
<script type="text/javascript" charset="utf-8">    
  $(document).ready(function(){
 
    // The example text strings
    var column1Label = 'Examples';
    var column1Example = '11:45 am';   
    var column2Example = 'Work';   
    var column3Example = '15oz';   
 
    // Identify the question
    var thisQuestion = $('#question{QID}');
    var thisArray = $('th.answertext:eq(0)', thisQuestion).closest('table');
 
    // Create a fake row
    var newRow = $('tbody:eq(0) tr:eq(0)', thisArray).clone();
    $(newRow).addClass('inserted-row');
    $('input[type="text"]', newRow).removeAttr('id').removeAttr('name');
    $('input[type="hidden"]', newRow).remove();
 
    // Insert the example text strings
    $('.answertext', newRow).text(column1Label);
    $('input[type="text"]:eq(0)', newRow).val(column1Example);
    $('input[type="text"]:eq(1)', newRow).val(column2Example);
    $('input[type="text"]:eq(2)', newRow).val(column3Example);
 
    // Disable the fake row inputs
    $('input[type="text"]', newRow).attr('readonly', true);
 
    // Insert the fake row
    $('tbody:eq(0)', thisArray).prepend(newRow);
 
    // Fix up the row classes
    var rowClass = 1;
    $('tbody tr', thisArray).each(function(i) {
      if($(this).hasClass('sub-header-row')) {
        rowClass = 1
      }
      else {
        rowClass++;
        $(this).removeClass('array1 array2')
        if(rowClass % 2 == 0) {
          $(this).addClass('array2');
        }
        else {
          $(this).addClass('array1');
        }
      }
    });  
 
    });
</script>

Survey for 1.92 attached:

File Attachment:

File Name: limesurvey...8745.lss
File Size:24 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: jess29
The topic has been locked.
  • jess29
  • jess29's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
8 years 8 months ago #132688 by jess29
The topic has been locked.
  • jess29
  • jess29's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
8 years 8 months ago #132689 by jess29
Replied by jess29 on topic Example Row in Text Array
You beat me to it. That works! I'll throw that in mine Monday morning and with a few edits, should be good to go. Will let you know either way. Thanks!
The topic has been locked.
  • jess29
  • jess29's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
8 years 7 months ago #132846 by jess29
Replied by jess29 on topic Example Row in Text Array
Works great! Thank you!!
The topic has been locked.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose