- Posts: 10611
- Thank you received: 3691
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Array Question with "Other" Answer
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
6 years 4 months ago #159846
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Array Question with "Other" Answer
I don't understand the question. The example above gives 3 "Other" inputs and can easily be expanded for more.
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- miguelvillegas88
- Offline
- New Member
Less
More
- Posts: 19
- Thank you received: 0
6 years 4 months ago #159853
by miguelvillegas88
Replied by miguelvillegas88 on topic Array Question with "Other" Answer
im sorry, i was confused
The topic has been locked.
- miguelvillegas88
- Offline
- New Member
Less
More
- Posts: 19
- Thank you received: 0
6 years 4 months ago #159901
by miguelvillegas88
Replied by miguelvillegas88 on topic Array Question with "Other" Answer
HI, Im sorry can you help me, i want to put de other´s textbox in a X Axis, like the image
this is the script
thanks
<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 question
$(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 input
$('.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 input(s) 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>
this is the script
thanks
<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 question
$(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 input
$('.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 input(s) 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>
Attachments:
The topic has been locked.
- DVP17lemon
- Offline
- New Member
Less
More
- Posts: 9
- Thank you received: 0
5 years 9 months ago - 5 years 9 months ago #169994
by DVP17lemon
Replied by DVP17lemon on topic Array Question with "Other" Answer
Thanks @tpartner for this great code!
However, I only wanted to ask if there is also a way to accomplish this without using JavaScript? @DenisChenu has posted something that seems to go into this direction. Unfortunately, it is not fully clear how his example actually works. Does anybody have a detailed explanation of @DenisChenu's post or how to accomplish this without using JavaScript?
However, I only wanted to ask if there is also a way to accomplish this without using JavaScript? @DenisChenu has posted something that seems to go into this direction. Unfortunately, it is not fully clear how his example actually works. Does anybody have a detailed explanation of @DenisChenu's post or how to accomplish this without using JavaScript?
Last edit: 5 years 9 months ago by DVP17lemon.
The topic has been locked.
- DenisChenu
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13910
- Thank you received: 2548
5 years 9 months ago #170003
by DenisChenu
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
Replied by DenisChenu on topic Array Question with "Other" Answer
I never put any code about a solution to integrate "other free text" in the array .
Just the simple Expression manager system to fill sub questions with another question : master.sondages.pro/919152
Just the simple Expression manager system to fill sub questions with another question : master.sondages.pro/919152
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10611
- Thank you received: 3691
5 years 9 months ago #170019
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Array Question with "Other" Answer
Well, still with JavaScript, but this may be a better solution - the "Other" or "Comments" fields are in modal (pop up) dialogs.
www.limesurvey.org/forum/can-i-do-this-w...elds?start=15#168906
www.limesurvey.org/forum/can-i-do-this-w...elds?start=15#168906
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- rizkiheryandi
- Offline
- New Member
Less
More
- Posts: 19
- Thank you received: 1
5 years 4 months ago #176233
by rizkiheryandi
Replied by rizkiheryandi on topic Array Question with "Other" Answer
Wow, big effort for answering with javascript solution everywhere, i appreciate and you all amazing guys
But im scare about the result of the input, would it be a big trouble when we collect the data and export for analysing it ?
Because we add more our own input field and not from the official system
Im new with LS, but in my logic it can be happen, but maybe it's not a problem when you create javascript and you know what are you doing
Thanks !!
(Answering the "4 years ago of thread" maybe my answer it's invalid)
But im scare about the result of the input, would it be a big trouble when we collect the data and export for analysing it ?
Because we add more our own input field and not from the official system
Im new with LS, but in my logic it can be happen, but maybe it's not a problem when you create javascript and you know what are you doing
Thanks !!
(Answering the "4 years ago of thread" maybe my answer it's invalid)
The topic has been locked.
- Mazi
- Offline
- Official LimeSurvey Partner
1 year 5 months ago #232524
by Mazi
You can test the feature at plugins.mysurveyhosting.com/index.php/362484?newtest=Y&lang=en and download the plugin at survey-consulting.com/product/array-with...xt-limesurvey-plugin .
Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
Replied by Mazi on topic Array Question with "Other" Answer
Yes, for Limesurvey 3.x and 5.x there is an easy to use plugin which allows adding 1-x other free text fields to array questions, see attached screenshots.Thanks @tpartner for this great code!
However, I only wanted to ask if there is also a way to accomplish this without using JavaScript?
You can test the feature at plugins.mysurveyhosting.com/index.php/362484?newtest=Y&lang=en and download the plugin at survey-consulting.com/product/array-with...xt-limesurvey-plugin .
Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
The topic has been locked.