Check out the LimeSurvey source code on GitHub!
Welcome, Guest
Username: Password:

TOPIC: Slider Question in reverse order

Slider Question in reverse order 2 years 3 months ago #111692

Hi,

I have a question "Multiple numerical input" which I am using as Slider. Currently the slider is displayed as 0 - 5. What I want to do is to display the slider from 5 - 0. Can you please suggest how can I do this.

Prompt response would be greatly appreciated.

Thanks in advance.
The administrator has disabled public write access.

Slider Question in reverse order 2 years 3 months ago #111697

  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5428
  • Thank you received: 809
  • Karma: 240
First of all: You don't need to write "prompt response would be greatly appreciated". It will not gonna be responded faster this way. If people have an answer, they'll give it to you. If not, not.

Now to your issue: How about writing 5 into slider minimum value and 1 into slider maximum value?
It shows correct for me, but I face one problem: The slider can't be moved. When I go for 1-5 instead 5-1 the slider seems to work fine.
Have a look at the manual! It is a really valuable source for information. Here some helpful links:
Manual (EN) | Question Types | [url=https://manual.limesurvey.org/Workarounds[/url]

If you found this answer helpful and it saved you some time please consider a [url=https://donate.limesurvey.org[/url] to the...
The administrator has disabled public write access.

Slider Question in reverse order 2 years 3 months ago #111717

  • Mazi
  • Mazi's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6029
  • Thank you received: 373
  • Karma: 260
Sliders always go from left/min to right/max and thus holch's idea doesn't work because 5 > 1 -> wrong min/max.

Instead, use an array question with a blank sub question and add answer 5 - ... - 1.

Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"
The administrator has disabled public write access.

Slider Question in reverse order 2 years 3 months ago #111729

  • tpartner
  • tpartner's Avatar
  • Online
  • LimeSurvey Team
  • Posts: 6570
  • Thank you received: 1477
  • Karma: 579
There is no "reverse slide" functionality for the jQuery UI slider but it can be mimicked by replacing the slide function and subtracting the slider value from the slider maximum.

Of course, we would also need to handle things like the show-min, show-max, steps, and decimal places in the accuracy.

So, here's a quick workaround with the following caveats:
- Developed for LS 2.05
- Only tested in IE7-10, Firefox and Chrome
- The "Reset" button will not work

1) Add the following function to the end of template.js:
function reverseSlider(qID) {
 
	// Identify the question
	var thisQuestion = $('#question'+qID);
 
	//$('span.input', thisQuestion).show() // un-comment this to debug
 
	// Reverse the min/max displays
	$('.answer-item', thisQuestion).each(function(i) {
		var showMinText = $('.slider-showmin', this).text();
		var showMaxText = $('.slider-showmax', this).text();
		$('.slider-showmin', this).text(showMaxText);
		$('.slider-showmax', this).text(showMinText);
	});
 
	// Initial slider positions
	$('span.input input[type="text"]', thisQuestion).each(function(i) {
 
		if($(this).val() != '') {				
			var thisRow = $(this).closest('li.answer-item');				
			var thisSlider = $('.ui-slider', thisRow);
			var sliderValue = $(thisSlider).slider('option', 'max')+$(thisSlider).slider('option', 'min')-$(this).val();
			$('.ui-slider', thisRow).slider('option', 'value', sliderValue);
			$('.slider-callout', thisRow).text($(this).val()); 
		}
	});
 
	// New slide function
	$('.ui-slider', thisQuestion).slider( 'option', 'slide', function(event, ui) {		
		// Define a few vars
		var thisRow = $(this).closest('li.answer-item');
		var thisSlider = $(this);
		var step = $(thisSlider).slider('option', 'step').toString();
		var stepDecimals = '';
		if(step.indexOf('.') != -1) {
			stepDecimals = step.length - (step.indexOf('.')+1);
		}
		var reverseValue = '';
 
		// Calculate the "reverse" value
		if(ui.value > $(thisSlider).slider('option', 'max')) {
			reverseValue = $(thisSlider).slider('option', 'min');
		}
		else if(ui.value < $(thisSlider).slider('option', 'min')) {
			reverseValue = $(thisSlider).slider('option', 'max');
		}
		else if(stepDecimals > 0) { // Handle decimal places
			reverseValue = ($(thisSlider).slider('option', 'max')+$(thisSlider).slider('option', 'min')-ui.value).toFixed(stepDecimals);
		}
		else{
			reverseValue = $(thisSlider).slider('option', 'max')+$(thisSlider).slider('option', 'min')-ui.value;
		}
		reverseValue = reverseValue.toString();
		reverseValue = reverseValue.replace(/\./,LSvar.sLEMradix);
 
		// Load the callout
		$('.slider_callout', thisRow).text(reverseValue);
 
		// Set the data value
		$('input.text', thisRow).val(reverseValue);
		$('input.text', thisRow).triggerHandler("keyup");
	});
}

2) Add this script to the source of every question you want to "reverse":
<script type="text/javascript" charset="utf-8">	
    $(document).ready(function() { 	
		reverseSlider({QID});
	});
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The administrator has disabled public write access.

Slider Question in reverse order 2 years 3 months ago #111732

  • Mazi
  • Mazi's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6029
  • Thank you received: 373
  • Karma: 260
Wow, thanks for all your work on this, Tony.

Please add this to the workarounds section of the manual so your valuable work doesn't get lost.

Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"
The administrator has disabled public write access.

Slider Question in reverse order 1 year 10 months ago #116116

  • tpartner
  • tpartner's Avatar
  • Online
  • LimeSurvey Team
  • Posts: 6570
  • Thank you received: 1477
  • Karma: 579
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The administrator has disabled public write access.
Time to create page: 0.250 seconds
Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form