Welcome to the LimeSurvey Community Forum

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

Order a questions

  • psoliveira
  • psoliveira's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
7 years 3 months ago #147610 by psoliveira
Order a questions was created by psoliveira
Hi everybody,

I want to order a array based on the current week day.
I know that limesurvey allows to order randomly a question and there are some workarounds for this too. But my order is specify and not random.
If someone answers on a thursday, that should be the first item from the list and go down (wednesday, tuesday, monday...) and this should always change depending on the day of the week the survey is taken.

Thank you for your help.
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 2 months ago - 7 years 2 months ago #147629 by DenisChenu
Replied by DenisChenu on topic Order a questions
Hi,

No way to have a specific order currently : i have a very old fork about this issue.

We a feature request about order of answer/sub-question : bugs.limesurvey.org/view.php?id=11988

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.
Last edit: 7 years 2 months ago by DenisChenu.
The topic has been locked.
  • holch
  • holch's Avatar
  • Online
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 2 months ago #147633 by holch
Replied by holch on topic Order a questions
I was thinking about this and while there is no way to order this out of the box, but as a workaround you could create 7 questions for this, with the respective order. Now you would just need to figure out how to find out which day of the week it is to show one of these questions and hide the others. Later you will have join these for analysis. Is probably doable via Javascript.

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 2 months ago #147647 by tpartner
Replied by tpartner on topic Order a questions
Assuming you set up the array sub-questions ordered Sunday-Saturday, adding this script to the source of the array should do the trick:

Code:
<script type="text/javascript" charset="utf-8">
  $(document).ready(function() {
 
    // Identify this question
    var thisQuestion = $('#question{QID}');
 
    // Identify the day of the week
    var todayDate = new Date();
    var weekDay = todayDate.getDay();
 
    // Move the array rows      
    $('tr.answers-list:lt('+weekDay+')', thisQuestion).appendTo($('table.subquestion-list tbody:eq(0)', thisQuestion));
    });
 
</script>

Sample survey attached:

File Attachment:

File Name: limesurvey...1-24.lss
File Size:22 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: DenisChenu
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 2 months ago - 7 years 2 months ago #147648 by tpartner
Replied by tpartner on topic Order a questions
Oops, sorry, I mis-read the order that you want. If you order the sub-questions reversed Saturday, Friday...Monday,Sunday, use this script:

Code:
<script type="text/javascript" charset="utf-8">
  $(document).ready(function() {
 
    // Identify this question
    var thisQuestion = $('#question{QID}');
 
    // Identify the day of the week
    var todayDate = new Date();
    var weekDay = todayDate.getDay();
    var reverseWeekDay = 6-weekDay
 
    // Move the array rows      
    $('tr.answers-list:lt('+(reverseWeekDay)+')', thisQuestion).appendTo($('table.subquestion-list tbody:eq(0)', thisQuestion));
    });
 
</script>

Sample survey:

File Attachment:

File Name: limesurvey...9891.lss
File Size:22 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 7 years 2 months ago by tpartner.
The following user(s) said Thank You: psoliveira
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 2 months ago - 7 years 2 months ago #147650 by DenisChenu
Replied by DenisChenu on topic Order a questions
tpartner solution are better, becaus i have no idea to set the order depend on day of the week in Expression Manager with this new plugin : framagit.org/SondagePro-LimeSurvey-plugi...Ordering/tree/master

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.
Last edit: 7 years 2 months ago by DenisChenu.
The following user(s) said Thank You: psoliveira
The topic has been locked.
  • psoliveira
  • psoliveira's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
7 years 2 months ago #147704 by psoliveira
Replied by psoliveira on topic Order a questions
This works perfectly.
Thanks tpartner.
The topic has been locked.
  • psoliveira
  • psoliveira's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
7 years 2 months ago #147709 by psoliveira
Replied by psoliveira on topic Order a questions
I also tried this on a array but doesn't work. Any idea why?
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 2 months ago #147710 by tpartner
Replied by tpartner on topic Order a questions
I don't understand the question. The attached examples are arrays and they do work.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • psoliveira
  • psoliveira's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
7 years 2 months ago #147711 by psoliveira
Replied by psoliveira on topic Order a questions
Sorry, i meant a texts array.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 2 months ago - 7 years 2 months ago #147743 by tpartner
Replied by tpartner on topic Order a questions
This should work for normal ordering (Sunday,Monday...Friday,Saturday):
Code:
<script type="text/javascript" charset="utf-8">
  $(document).ready(function() {
 
    // Identify this question
    var thisQuestion = $('#question{QID}');
 
    // Identify the day of the week
    var todayDate = new Date();
    var weekDay = todayDate.getDay();
 
    // Move the array rows      
    $('table.subquestion-list tr[id^="javatbd"]:lt('+weekDay+')', thisQuestion).appendTo($('table.subquestion-list tbody:eq(0)', thisQuestion));
    });
</script>


And this for reverse ordering (Saturday, Friday...Monday,Sunday):
Code:
<script type="text/javascript" charset="utf-8">
  $(document).ready(function() {
 
    // Identify this question
    var thisQuestion = $('#question{QID}');
 
    // Identify the day of the week
    var todayDate = new Date();
    var weekDay = todayDate.getDay();
    var reverseWeekDay = 6-weekDay
 
    // Move the array rows      
    $('table.subquestion-list tr[id^="javatbd"]:lt('+(reverseWeekDay)+')', thisQuestion).appendTo($('table.subquestion-list tbody:eq(0)', thisQuestion));
    });
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 7 years 2 months ago by tpartner.
The following user(s) said Thank You: psoliveira
The topic has been locked.
  • psoliveira
  • psoliveira's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
7 years 2 months ago #147752 by psoliveira
Replied by psoliveira on topic Order a questions
Thank you again tpartner.
I've also used this on a multiple numerical input.

Here's the code for the reverse ordering:
Code:
<script type="text/javascript" charset="utf-8">
  $(document).ready(function() {
 
    // Identify this question
    var thisQuestion = $('#question{QID}');
 
    // Identify the day of the week
    var todayDate = new Date();
    var weekDay = todayDate.getDay();
    var reverseWeekDay = 6-weekDay
 
    // Move the array rows      
    $('table.table-multi-num tr[id^="javatbd"]:lt('+(reverseWeekDay)+')', thisQuestion).appendTo($('table.table-multi-num tbody:eq(0)', thisQuestion));
    });
</script>

And the code for normal ordering:
Code:
<script type="text/javascript" charset="utf-8">
  $(document).ready(function() {
 
    // Identify this question
    var thisQuestion = $('#question{QID}');
 
    // Identify the day of the week
    var todayDate = new Date();
    var weekDay = todayDate.getDay();
 
    // Move the array rows      
    $('table.table-multi-num tr[id^="javatbd"]:lt('+(weekDay)+')', thisQuestion).appendTo($('table.table-multi-num tbody:eq(0)', thisQuestion));
    });
</script>
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose