Welcome to the LimeSurvey Community Forum

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

Adding a number to rankings

  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 1 month ago #195522 by tpartner
Replied by tpartner on topic Adding a number to rankings
Although I found that e.data was undefined, Denis' solution is far more elegant.

Code:
<script type="text/javascript" charset="utf-8">
 
  $(document).on('ready pjax:scriptcomplete',function(){  
 
    var thisQuestion = $('#question{QID}');
 
    // Listener on the hidden ranking <select /> elements
    $('.select-item select', thisQuestion).on('change', function(e) {
      $('.sortable-rank .inserted-rank', thisQuestion).remove();
 
      $('.sortable-rank .answer-item', thisQuestion).each(function(i) {
        $(this).prepend('<span class="inserted-rank">'+(i+1)+': </span>');
      });
    });
    });
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 1 month ago #195588 by DenisChenu
Replied by DenisChenu on topic Adding a number to rankings

tpartner wrote: Although I found that e.data was undefined, Denis' solution is far more elegant.

Maybe but your's work on more LimeSurvey version ;)

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.
More
3 years 9 months ago - 3 years 9 months ago #202898 by dostoyevski2015
Replied by dostoyevski2015 on topic Adding a number to rankings
Hi there,

I used Tony's first script to add this function in my survey. It did the job but created another problem that I cannot get around.

The issue is that those answers that are to be ranked in my survey are derived from previous pages, using placeholders. Without this script, the placeholder function works fine. However with this script in question source, LimeSurvey stops recognizing placeholders as placeholders and display them as text (please see the attachment).

What could be the reason of this problem? Thank you in advance.

I'm using LimeSurvey Public 2.67.3 Version

Last edit: 3 years 9 months ago by dostoyevski2015.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 9 months ago #202905 by tpartner
Replied by tpartner on topic Adding a number to rankings
Can you attach a small sample survey (.lss file) containing only the relevant questions?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
3 years 9 months ago #202912 by dostoyevski2015
Replied by dostoyevski2015 on topic Adding a number to rankings
Sure, please find it below. There are four pages in this trial survey: The first two of them are multiple short text questions. The third and the fourth pages are to rank those multiple short text answers. As you can see, the placeholder in the third page works well without the script. However, the script in the fourth page disrupts the placeholder function. I want to have both the script and the placeholder functions at the same time eventually.

p.s.: Sorry the buttons and so are in German

File Attachment:

File Name: limesurvey...5944.lss
File Size:35 KB
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 9 months ago #202917 by holch
Replied by holch on topic Adding a number to rankings
By the way: LimeSurvey 2.67.3 is from 28.07.2017, so this version is almost 3 years old, unpatched, without updates. Even within the same branch, there have been newer versions, but this branch for sure has been one of the worst branches of Limesurvey with a lot of bugs, especially at the beginning.

I would highly recommend to update to LS 3.x LTS. Currently I would not use LS 4.x in production, as it has a similar history as 2.5x, which you are using.

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
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 9 months ago #202939 by tpartner
Replied by tpartner on topic Adding a number to rankings
There appears to be a conflict between the script and Expression Manager in that version but I don't see where and see no JavaScript errors.

I also suggest updating your installation.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 9 months ago #202942 by tpartner
Replied by tpartner on topic Adding a number to rankings
Oh, wait, it's because Expression Manager is trying to parse the inserted styles. Use this script (note the inserted spaces after the opening curly braces of the style rules):

Code:
<script type="text/javascript" charset="utf-8">
  $(document).ready(function(){  
 
    // Identify this question
    var qID = {QID};
    var thisQuestion = $('#question'+qID);
 
    // Listeners on the rankable items
    $('.ui-sortable', thisQuestion).on('sortstop', function(event, ui) {
      insertRankIndicators();
    });      
    $('.ui-sortable li', thisQuestion).on('dblclick', function(event, ui) {
 
      setTimeout(function() {
        insertRankIndicators();
      }, 100);
    });
 
    // A function to insert ranking indicators
    function insertRankIndicators() {
      $('.inserted-rank', thisQuestion).remove();
      $('.dragDropRankList li', thisQuestion).each(function(i) {
        $(this).append('<span class="inserted-rank">Nr.'+(i+1)+'</span>');
      });
    }
 
    // Insert some styles (these could be in template.css)
    var newStyles = '.ui-sortable-handle { \
              position: relative;\
            }\
            .ui-sortable li .inserted-rank { \
              position: absolute;\
              top: 5px;\
              right: 5px;\
            }';  
    $('head').append('<style type="text/css">'+newStyles+'</style>');  
  });    
</script>

Sample survey attached:

File Attachment:

File Name: limesurvey...4(3).lss
File Size:35 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: dostoyevski2015
The topic has been locked.
More
3 years 9 months ago #202967 by dostoyevski2015
Replied by dostoyevski2015 on topic Adding a number to rankings
That works, Tony, thanks!

You both are right, that this version needs to be updated. I just need to use it as my institution does (bureaucratic hurdles...)
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose