Welcome to the LimeSurvey Community Forum

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

string instead of number in slider

  • supernul
  • supernul's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
6 years 10 months ago #152664 by supernul
string instead of number in slider was created by supernul
Hello everybody,


I created a question with a slider and I would like to show a string rather than a number above the cursor of the slider.

For instance:


... is less important than ...

option A ...
O---- ... option B




... is as important as ...

option A ...
O
... option B


Is it possible to use javascript as for the array multiple numeric to replace numbers by string ? I hope but I do not see how to do this.

I found solutions modifying template.css and other files but I cannot modify them.

Thank you for your help.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 10 months ago - 6 years 10 months ago #152671 by tpartner
Replied by tpartner on topic string instead of number in slider
This script when inserted in the text of a slider question will replace the slider call-out values with custom labels. This demonstration script is for LS version 2.64.7 and uses a slider with values from 1-5.

Code:
<script type="text/javascript" charset="utf-8">
  $(document).ready(function(){  
 
    // Identify this question
    var thisQuestion = $('#question{QID}');
 
    // Define the new labels
    var labels = {
      1: 'Is much less important than', 
      2: 'Is less important than', 
      3: 'Is as important as', 
      4: 'Is more important than', 
      5: 'Is much more important than'
    };
 
    // Initial slider state
    $('.question-item', thisQuestion).each(function(i) {
      var thisRow = $(this);
      $('input[type="text"]', thisRow).on('slideEnabled', function(event, ui) {
        $('.tooltip-inner', thisRow).addClass('hidden');
        $('.tooltip', thisRow).append('<div class="tooltip-inner inserted">'+labels[$('input[type="text"]', thisRow).val()]+'</div>');
        $('.tooltip', thisRow).css('margin-left', '-'+($('.tooltip', thisRow).width()/2)+'px');
      });
    });
 
    // Listener on sliders
    $('input[type="text"]', thisQuestion).on('slide slideStop', function(event, ui) {
      var thisRow = $(this).closest('.question-item');
      $('.tooltip-inner.inserted', thisRow).text(labels[$('input[type="text"]', thisRow).val()]);
      $('.tooltip', thisRow).css('margin-left', '-'+($('.tooltip', thisRow).width()/2)+'px');
      checkconditions($(this).val(), $(this).attr('name'), 'text');
    });
  });
</script>

Sample survey attached:

File Attachment:

File Name: limesurvey...4-19.lss
File Size:17 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 6 years 10 months ago by tpartner.
The following user(s) said Thank You: supernul
The topic has been locked.
  • supernul
  • supernul's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
6 years 10 months ago #152710 by supernul
Replied by supernul on topic string instead of number in slider
Thank you very much. That is more than I expected. It is exactly what I am looking for.
The topic has been locked.
  • tammo
  • tammo's Avatar
  • Offline
  • Official LimeSurvey Partner
  • Official LimeSurvey Partner
More
6 years 10 months ago #152712 by tammo
Replied by tammo on topic string instead of number in slider
Wow, Tony, I see so many solutions here. Did you ever think of publishing them in a searchable way, like in a Wiki/website of just LS solutions?

Tammo


Tammo ter Hark at Respondage
For Limesurvey reporting, education and customized themes
respondage.nl
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 10 months ago #152723 by tpartner
Replied by tpartner on topic string instead of number in slider

Did you ever think of publishing them in a searchable way, like in a Wiki/website of just LS solutions?

Nope - too much work/maintenance so I just put the larger ones in the LS workarounds section . When time allows, I will convert this one to a jQuery plugin to make it a little more user-friendly and add it to the workarounds.

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
4 years 10 months ago #183681 by fair_lady
Replied by fair_lady on topic string instead of number in slider
Hello everyone,

and thank you, tpartner for the very helpful script. I used it for a while and it worked perfectly. No I have updated Limesurvey to Version 3.15.9+190214 and I can't find a way to make the slider work again.
Is there a similar script for the newer version of Limesurvey?

Thanks in advance for any suggestions on how to do this.

Cheers
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 10 months ago #183683 by tpartner
Replied by tpartner on topic string instead of number in slider

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
4 years 10 months ago #183684 by fair_lady
Replied by fair_lady on topic string instead of number in slider
Perfect! Thanks a lot!
I have somehow missed this!
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose