- Posts: 61
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Array randomize with "Other" text field
- vzyldd
- Topic Author
- Offline
- Senior Member
Less
More
1 month 2 weeks ago #258433
by vzyldd
Array randomize with "Other" text field was created by vzyldd
Please help us help you and fill where relevant:
Your LimeSurvey version: LimeSurvey Community Edition Version 5.4.15+221212
Own server or LimeSurvey hosting: Own
Survey theme/template: Fruity
==================
Greetings.
I need to keep the last option at the end of an array when randomizing the sub-questions. The problem is that the last sub-question also contains a text field (inserted using a script & instructions from Tony). I tried fixing the position of the last sub-question using another Tony script (as below). Without the text field inserted, this works perfect. With the text field inserted, randomization also moves this text field and does not keep it with the last sub-question. Any ideas how I can keep the last sub-question and the text field together?
lss attached.<script type="text/javascript" charset="utf-8">
$(document).on('ready pjax:complete',function() {
// Define the subquestion code to be fixed at the bottom of the array
var fixedCode = '10';
// Move that row to the bottom
$('#question{QID} table.subquestion-list tbody:eq(0)').append($('tr[id$="X{QID}'+fixedCode+'"]'));
// Fix up the row background colours
$('#question{QID} tr.answers-list'). each (function(i){
$(this).removeClass('ls-even, ls-odd');
if(i % 2 == 0) {
$(this).addClass('ls-even');
}
else {
$(this).addClass('ls-odd');
}
});
});
</script>
Your LimeSurvey version: LimeSurvey Community Edition Version 5.4.15+221212
Own server or LimeSurvey hosting: Own
Survey theme/template: Fruity
==================
Greetings.
I need to keep the last option at the end of an array when randomizing the sub-questions. The problem is that the last sub-question also contains a text field (inserted using a script & instructions from Tony). I tried fixing the position of the last sub-question using another Tony script (as below). Without the text field inserted, this works perfect. With the text field inserted, randomization also moves this text field and does not keep it with the last sub-question. Any ideas how I can keep the last sub-question and the text field together?
lss attached.<script type="text/javascript" charset="utf-8">
$(document).on('ready pjax:complete',function() {
// Define the subquestion code to be fixed at the bottom of the array
var fixedCode = '10';
// Move that row to the bottom
$('#question{QID} table.subquestion-list tbody:eq(0)').append($('tr[id$="X{QID}'+fixedCode+'"]'));
// Fix up the row background colours
$('#question{QID} tr.answers-list'). each (function(i){
$(this).removeClass('ls-even, ls-odd');
if(i % 2 == 0) {
$(this).addClass('ls-even');
}
else {
$(this).addClass('ls-odd');
}
});
});
</script>
Attachments:
Please Log in to join the conversation.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3595
1 month 2 weeks ago - 2 weeks 17 hours ago #258493
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 randomize with "Other" text field
It's all about the order in which portions of the script are executed.
You want to fix the row at the bottom before moving the text input.
Sample survey:
You want to fix the row at the bottom before moving the text input.
Code:
<script type="text/javascript" data-author="Tony Partner"> $(document).on('ready pjax:scriptcomplete',function(){ // Define the subquestion code to be fixed at the bottom of the array var fixedCode = '10'; // Identify the questions var qID = {QID}; var thisQuestion = $('#question'+qID); var nextQuestion = thisQuestion.nextAll('.text-short:eq(0)'); // Move the fixed row to the bottom $('table.subquestion-list tbody:eq(0)', thisQuestion).append($('tr[id$="X'+qID+fixedCode+'"]')); // Fix up the row background colours $('tr.answers-list', thisQuestion). each (function(i){ $(this).removeClass('ls-even ls-odd'); if(i % 2 == 0) { $(this).addClass('ls-even'); } else { $(this).addClass('ls-odd'); } }); // Hide the next question nextQuestion.hide(); // Move the text input $('tr[id^="javatbd"]:last th.answertext', thisQuestion).append($('.answer-item', nextQuestion)); // Clean-up styling $('th.answertext .answer-item', thisQuestion).css({ 'padding': 0 }); $('th.answertext .answer-item div', thisQuestion).css({ 'padding': 0 }); }); </script>
Sample survey:
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 2 weeks 17 hours ago by tpartner.
The following user(s) said Thank You: vzyldd
Please Log in to join the conversation.
- vzyldd
- Topic Author
- Offline
- Senior Member
Less
More
- Posts: 61
- Thank you received: 0
1 month 1 week ago #258670
by vzyldd
Replied by vzyldd on topic Array randomize with "Other" text field
Thank you Tony. Perfect. Much appreciated.
Please Log in to join the conversation.