Welcome to the LimeSurvey Community Forum

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

Combine Array(Text) with short free text

  • kratugoel
  • kratugoel's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
4 years 1 month ago #193543 by kratugoel
Combine Array(Text) with short free text was created by kratugoel
I have an array(text) question with number input only. It has an Others subquestion as part of it and I would like to insert a comment box for users to specify "others"

Any assistance in this regard?
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 1 month ago #193549 by Joffm
Replied by Joffm on topic Combine Array(Text) with short free text
Hi,
here is something.
This solution uses the script for a normal array, so there are still parts that refer to radio buttons.



Joffm

File Attachment:

File Name: limesurvey...9874.lss
File Size:23 KB

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • kratugoel
  • kratugoel's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
4 years 1 month ago #193552 by kratugoel
Replied by kratugoel on topic Combine Array(Text) with short free text
I am getting the following message when I try to import your survey.

Internal Server Error
Property "SurveyLanguageSetting.surveyls_policy_notice" is not defined.
An internal error occurred while the Web server was processing your request. Please contact the webmaster to report this problem.

Thank you.
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 1 month ago #193554 by Joffm
Replied by Joffm on topic Combine Array(Text) with short free text
This is because these policy settings were implemented in LS version 3.x.

So, you obviously don't use an actual version.
But you did not mention it.

So, what version are you using?

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • kratugoel
  • kratugoel's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
4 years 1 month ago #193555 by kratugoel
Replied by kratugoel on topic Combine Array(Text) with short free text
LimeSurvey Version 2.06+ Build 151215

But you had earlier shared another sample survey and that worked. It is attached here.
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 1 month ago #193556 by Joffm
Replied by Joffm on topic Combine Array(Text) with short free text
Open the lss in a text editor and remove ALL lines that contain "policy".

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • kratugoel
  • kratugoel's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
4 years 1 month ago #193559 by kratugoel
Replied by kratugoel on topic Combine Array(Text) with short free text
It almost worked. I am trying to get it in the second last row instead. I need the totals to appear as well.

I have zero experience with Java and hence the struggle.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 1 month ago #193562 by tpartner
Replied by tpartner on topic Combine Array(Text) with short free text
Please post your code.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • kratugoel
  • kratugoel's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
4 years 1 month ago #193563 by kratugoel
Replied by kratugoel on topic Combine Array(Text) with short free text
<script type="text/javascript" charset="utf-8">

$(document).ready(function() {

// Identify the questions
var thisQuestion = $('#question'+{QID}+'');
var nextQuestion1 = $(thisQuestion).nextAll('.text-short:eq(0)');
var nextQuestion2 = $(thisQuestion).nextAll('.text-short:eq(1)');
var nextQuestion3 = $(thisQuestion).nextAll('.text-short:eq(2)');
var nextQuestions = $(nextQuestion1).add(nextQuestion2).add(nextQuestion3);
var nextLength = nextQuestions.length;
var sqLength = ('tr.answers-list', thisQuestion).length;

// Hide the short-text questions
$(nextQuestions).hide();

// Move the hidden text inputs into the array
for (i = 0; i < nextLength; i++) {
var workingIndex = (sqLength - 1) - (nextLength - i);
var nextQ = nextQuestions;
$('th.answertext:eq('+workingIndex+')', thisQuestion).append($('input[type="text"]', nextQ)).closest('tr').addClass('otherRow');
}

// Some styling...
$('input[type="text"]', thisQuestion).css({
'width': '50%'
});

// Handle the "Other" radios
$('input[type="text"]', thisQuestion).on('keyup change',function(event){
event.stopPropagation();

var thisRow = $(this).closest('tr.answers-list');
if($.trim($(this).val()) == '') {
$('input:radio[value!=""]', thisRow).prop('checked',false);
$('input:radio[value=""]', thisRow).click();
}
else {
$('input:radio[value=""]', thisRow).prop('checked',false);
}
});

// Handle the "Other" text inputs
$('.otherRow input.radio', thisQuestion).on('click',function(event){
var thisRow = $(this).closest('tr.answers-list');
if($(this).attr('value') == '') {
$('input[type="text"]', thisRow).val('');
}
});

// Validate the "Other" text inputs on submit
if($('#movenextbtn, #movesubmitbtn').attr('data-inserted-other') != 'true') { // We're only doing this once on this page
$('#movenextbtn, #movesubmitbtn').attr('data-inserted-other', 'true').on('click.insertedOther', function (event) {

var otherError = 0;

$('.array-flexible-row .otherRow').each(function(i) {

if(($('input:radio[value!=""]:checked', this).length > 0 && $('input[type="text"]', this).val() == '') || ($('input:radio[value!=""]:checked', this).length == 0 && $('input[type="text"]', this).val() != '')) {
otherError = 1;
}
});

if(otherError == 1) {
alert('Please review your answer in the "Other" row(s).');
return false;
}
});
}
});
</script>
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 1 month ago - 4 years 1 month ago #193564 by tpartner
Replied by tpartner on topic Combine Array(Text) with short free text
Try this (untested). I have also removed all of the necessary radio array stuff.

Code:
<script type="text/javascript" charset="utf-8">
 
  $(document).ready(function() {
 
    // Identify the questions
    var thisQuestion = $('#question'+{QID}+'');
    var nextQuestion1 = $(thisQuestion).nextAll('.text-short:eq(0)');
 
    // Hide the short-text question
    $(nextQuestion1).hide();
 
    // Move the hidden text input into the array (second last row)
    var rowCount = $('th.answertext', thisQuestion).length;
    $('th.answertext:eq('+(rowCount-2)+')', thisQuestion).append($('input[type="text"]', nextQuestion1)).closest('tr').addClass('otherRow');
 
    // Some styling...
    $('input[type="text"]', thisQuestion).css({
      'width': '50%'
    });
  });
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 4 years 1 month ago by tpartner.
The following user(s) said Thank You: kratugoel
The topic has been locked.
  • kratugoel
  • kratugoel's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
4 years 1 month ago #193565 by kratugoel
Replied by kratugoel on topic Combine Array(Text) with short free text
It worked perfectly. Thank you so much!
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 1 month ago #193616 by Joffm
Replied by Joffm on topic Combine Array(Text) with short free text
@Tony,

I knew you would do that.

As I am also very unexperienced in javascript I usually try to use one of your scripts and change, adapt it.
Sometimes it works, sometimes it does not.

You know I dream in Expression Manager. ;)

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose