Welcome to the LimeSurvey Community Forum

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

Slider Didn't work in Array (Number)

More
8 years 4 months ago - 8 years 4 months ago #153314 by nadirazakiya
Hello guys.. I want to make slider with array (number) based on this link www.limesurvey.org/manual/Workarounds:_Q...y-Dual-Scale-Numbers . The lsg file is attached. But the problem is the slider could not show. Anyone can help me?

Thank you.

Sorry my english is bad.
Last edit: 8 years 4 months ago by nadirazakiya.
The topic has been locked.
More
8 years 4 months ago #153325 by tpartner
As stated, that workaround is only tested in version 2.05. What version are you using?

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
8 years 4 months ago #153371 by nadirazakiya
I'm using version 2.64.7
The topic has been locked.
More
8 years 4 months ago #153402 by tpartner
Here is a workaround for version 2.6x.

Place this JavaScript in the question source:
Code:
<script type="text/javascript" charset="utf-8">
  $(document).ready(function() {
 
    insertSlider ({QID});
 
    function insertSlider (qID) {
 
      // Identify this question
      var thisQuestion = $('#question'+qID);
      thisQuestion.addClass('with-dropdown-sliders');
 
      // Loop through all array drop-downs
      $('select.multiflexiselect', thisQuestion).each(function(i, el){
        var thisCell = $(el).closest('td');
 
        // Hide the dropdown
        $(el).hide();
 
        // Some dropdown values
        var currentVal = $(el).val();
        var firstVal = Number($('option[value!=""]:first', el).attr('value'));
        var secondVal = Number($('option[value!=""]:eq(1)', el).attr('value'));
        var lastVal = Number($('option[value!=""]:last', el).attr('value'));
 
        // Insert an input for the slider
        var thisInput = $('<input class="inserted-input" type="text" />').insertAfter(el);
 
        // Initiate the slider
        thisInput.val(currentVal).bootstrapSlider({
          'min': firstVal,
          'max': lastVal,
          'step': secondVal - firstVal,
          'value': Number(currentVal),
          'tooltip': 'always'
        });
 
        // Listener on the slider
        $(thisInput).on('slideStop', function () {
          if($('.tooltip', thisCell).is(':hidden')) {
            $('.tooltip', thisCell).show();
            $('.tooltip', thisCell).css('margin-left', '-'+($('.tooltip', thisCell).width()/2)+'px');
          }
          $(el).val($(thisInput).val());
        });
 
        // Hide the slider call-out if no value selected yet
        if(currentVal == '') {
          $('.tooltip', thisCell).hide();
        }
      });
    }
  });
</script>

Place something like this at the end of template.css:
Code:
.with-dropdown-sliders .slider.slider-horizontal {
    margin: 1.5em auto  1em auto;
    width: 90%;
}
 
.with-dropdown-sliders .slider.slider-horizontal .slider-handle {
    margin-top: -5px;
}


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: nadirazakiya
The topic has been locked.
More
8 years 4 months ago #153442 by nadirazakiya
Hi Tony,
That's so cool,
I've implemented your code and it's work great.

Thank you very much.
The topic has been locked.
More
5 years 4 months ago #196681 by Christin8
Hello,
I'm trying the exact same thing, but this script doesn't work.
Is there also a workaround for version 3.21.1?
Thanks for help!
The topic has been locked.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose