- Posts: 21
- Thank you received: 1
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
How can i move an input text placed into an array(flexible text)
- FreshLemonUser
- Topic Author
- Offline
- Junior Member
Less
More
4 years 20 hours ago #197928
by FreshLemonUser
How can i move an input text placed into an array(flexible text) was created by FreshLemonUser
Hi Dear Guys, I hope everithing is going well despite the sitiation around the world..
How can i move an input text placed into an array(flexible text)?
i have this issue:
i´ve been following this to do it: www.limesurvey.org/forum/can-i-do-this-w...other-answer?start=0 , and this is a good moment to say thanks you to @tpartner, because it helps me...
I need an array with the som other fields, so i found how to put some other fields, but also i need to show a total, what i did was to use an array( multiflexible text) with a total by columns, then i´ve inserted the other fields into the array but i need fix their position.
this is the snipet that i´ve used to:
</p>
<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 nextQuestions = $(nextQuestion1).add(nextQuestion2);
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>
I´ll really apreciate your help.
Lime Survey Versión 3.22.14+200423 installed on my own server...
Regards..
How can i move an input text placed into an array(flexible text)?
i have this issue:
i´ve been following this to do it: www.limesurvey.org/forum/can-i-do-this-w...other-answer?start=0 , and this is a good moment to say thanks you to @tpartner, because it helps me...
I need an array with the som other fields, so i found how to put some other fields, but also i need to show a total, what i did was to use an array( multiflexible text) with a total by columns, then i´ve inserted the other fields into the array but i need fix their position.
this is the snipet that i´ve used to:
</p>
<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 nextQuestions = $(nextQuestion1).add(nextQuestion2);
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>
I´ll really apreciate your help.
Lime Survey Versión 3.22.14+200423 installed on my own server...
Regards..
The topic has been locked.
- Joffm
- Away
- LimeSurvey Community Team
Less
More
- Posts: 12931
- Thank you received: 3978
4 years 18 hours ago #197933
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic How can i move an input text placed into an array(flexible text)
Hi,
you referred to a post that started 6 years ago and was about a different type of question.
So to achieve this
you may use this
You see, you have to adapt some lines depending on the number of "Others".
Joffm
you referred to a post that started 6 years ago and was about a different type of question.
So to achieve this
you may use this
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)'); var nextQuestion2 = $(thisQuestion).nextAll('.text-short:eq(1)'); var nextQuestions = $(nextQuestion1).add(nextQuestion2); // Hide the short-text question $(nextQuestions).hide(); // Move the hidden text input into the array (second last row) var rowCount = $('th.answertext', thisQuestion).length; $('th.answertext:eq('+(rowCount-3)+')', thisQuestion).append($('input[type="text"]', nextQuestion1)).closest('tr').addClass('otherRow'); $('th.answertext:eq('+(rowCount-2)+')', thisQuestion).append($('input[type="text"]', nextQuestion2)).closest('tr').addClass('otherRow'); // Some styling... $('input[type="text"]', thisQuestion).css({ 'width': '50%' }); }); </script>
You see, you have to adapt some lines depending on the number of "Others".
Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
- FreshLemonUser
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 21
- Thank you received: 1
4 years 15 hours ago #197940
by FreshLemonUser
Replied by FreshLemonUser on topic How can i move an input text placed into an array(flexible text)
Hi @Joffm.
Thank you very much, you made my day happy ...
You are so kind.
It works perfect!!!
Thank you very much, you made my day happy ...
You are so kind.
It works perfect!!!
The topic has been locked.