Equation in multiple numercial inputs

More
1 year 1 week ago #143096 by urbana
urbana created the topic: Equation in multiple numercial inputs
Hi, I can't solve my problem with a relevance equation.
I have a question that asks for 4 Numbers.
(we ask for prices)
Minimum Price (mp)
Cheap Price (cp)
Expensive Price (ep)
Maximum Price (map)

Therefore I need a equation that checks:
Is mp < cp <ep < map
Is cp > mp <ep <map
Is ep > mp > cp < map
Is map > ep > cp > mp

An that is the tricky part I need to evaluate the single input and not to check for overall errors.
I could do it in JS but I struggle with the equation field and the manual is behind a lot versions.

Thx a lot!

urban-a :)

Please Log in to join the conversation.

More
1 year 1 week ago #143113 by jelo
jelo replied the topic: Equation in multiple numercial inputs
Use four single questions.
Allows more flexibility for validation. Also allows to display van Westendorp questions step by step or at once.

Please Log in to join the conversation.

More
1 year 1 week ago #143114 by urbana
urbana replied the topic: Equation in multiple numercial inputs
yes, that would make it easier
But due the new responsive designs every question takes a lot of space and I think breaks a lot of the intended design.

Please Log in to join the conversation.

More
1 year 1 week ago #143115 by jelo
jelo replied the topic: Equation in multiple numercial inputs

urbana wrote: But due the new responsive designs every question takes a lot of space and I think breaks a lot of the intended design.

Haven't used LS 2.5 but the spaced between questions can be changed and the templates/html will need to be optimized in the default templates as well. Multi numerical question type isn't offering enough control via EM or validation messages.
Get's quite messy when you don't want to have many warnings in the van westendorp question set. I normally show all questions on one page, but hide three of four at the start.

Please Log in to join the conversation.

More
1 year 3 days ago #143398 by tpartner
tpartner replied the topic: Equation in multiple numercial inputs
Here is a workaround for Van Westendorp Pricing Sliders - manual.limesurvey.org/Workarounds:_Manip...dorp_Pricing_Sliders

The sliders are dynamically controlled so when a slider is manipulated, all of the "higher" sliders are dynamically pushed to higher levels and "lower" sliders are pushed to lower levels. This ensures that the data will always be valid.


Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
The following user(s) said Thank You: DenisChenu

Please Log in to join the conversation.

More
1 month 3 weeks ago #158159 by Payek
Payek replied the topic: Equation in multiple numercial inputs
Hi everyone,
I'm trying to use the "Van Westendorp Pricing (2.5x)" on LimeSurvey version 2.67.3 + 170728. It seems to work, but I have found that data from intact sliders are not saved in DB. Only sliders moved by "hand" has value in DB. Sliders moved by "script" give an empty value, even if there is max/min value and slider is moved from default position by "script". I used sample survey from manual: Van Westendorp Pricing Sliders

Survey test is on my server, there: TEST Van Westendorp Pricing Sliders

Is it intentional behaviour or I made a mistake?

Thanks for any help,

Payek

Please Log in to join the conversation.

More
1 month 3 weeks ago #158163 by jelo
jelo replied the topic: Equation in multiple numercial inputs
I don't think you made a mistake.
There is a ongoing discussion about Slider touched / untouched with default values.
bugs.limesurvey.org/view.php?id=12264

There are bugs and different expectations.
You might open a bugreport with the workaround issue.

Please Log in to join the conversation.

More
1 month 3 weeks ago #158165 by tpartner
tpartner replied the topic: Equation in multiple numercial inputs
Bug found and fixed - I have updated the Workarounds section - manual.limesurvey.org/Workarounds:_Manip...ascript#Version_2.5x

This is the new code for template.js:

function shuffleArray(array) {
	for (var i = array.length - 1; i > 0; i--) {
		var j = Math.floor(Math.random() * (i + 1));
		var temp = array[i];
		array[i] = array[j];
		array[j] = temp;
	}
	return array;
}
 
 
/*****
    A jQuery plugin to facilitate the Van Westendorp pricing research methodology
    Copyright (C) 2016 - Tony Partner (http://partnersurveys.com)
    Licensed MIT, GPL
    Version - 2.0
    Create date - 19/10/16
*****/
(function( $ ){
 
	$.fn.vWPricing25 = function(options) {  
 
		var opts = $.extend( {
			order: [1, 2, 3, 4],
			randomOrder: false
		}, options);
 
		return this.each(function() { 
 
			var thisQuestion = $(this);
 
			thisQuestion.addClass('vwp-question');
 
			// Add some attributes and set the slider max/min values
			var itemsLength = $('.question-item', thisQuestion).length;
			$('.question-item', thisQuestion).each(function(i) {
				var thisInput = $('input[type=text]', this);
				var thisVal = $(thisInput).val();
 
				$(this).attr('data-item', (i+1));
				$(thisInput).attr('data-slider-index', (i+1));
 
				// Slider initial settings
				setTimeout(function() {	
					var thisSliderMin = $(thisInput).bootstrapSlider('getAttribute', 'min');
					$(thisInput).bootstrapSlider('setAttribute', 'min', thisSliderMin+(i));
					var thisSliderMax = $(thisInput).bootstrapSlider('getAttribute', 'max');
					$(thisInput).bootstrapSlider('setAttribute', 'max', thisSliderMax-((itemsLength-1)-i));
 
					if(thisVal == '') {
						$(thisInput).val('');
					}
 
				}, 200);
 
			});
 
			// Slider order
			if(opts.randomOrder == true) {
				shuffleArray(opts.order);
			}
			$(opts.order).each(function(i, val) {
				$('.subquestion-list.questions-list', thisQuestion).append($('.question-item[data-item="'+val+'"]', thisQuestion));
			});
 
			// Listeners on the sliders
			$('input[type=text]', thisQuestion).on('slide', function(event) {
				handleVwpSliders(this, $(this).bootstrapSlider('getValue'));
			});	
			$('input[type=text]', thisQuestion).on('slideStop', function(event) {
				handleVwpSliders(this, $(this).bootstrapSlider('getValue'));
			});
 
			// A function to handle the siders
			function handleVwpSliders(el, sliderVal) {
				var movedIndexNum = $(el).attr('data-slider-index');
 
				var lowerSliders = $('input[type=text]', thisQuestion).filter(function() {
					return $(this).attr('data-slider-index') < movedIndexNum;
				});
				var higherSliders = $('input[type=text]', thisQuestion).filter(function() {
					return $(this).attr('data-slider-index') > movedIndexNum;
				});
 
				$(lowerSliders).each(function(i) {
					var thisIndexNum = $(this).attr('data-slider-index');
					var newSliderVal = sliderVal-(movedIndexNum-thisIndexNum);
					if($(this).bootstrapSlider('getValue') > newSliderVal) {
						var thisRow = $(this).closest('.question-item');
						var thisTooltip = $('.tooltip', thisRow);
						$(this).bootstrapSlider('setValue', newSliderVal);
						$('.tooltip-inner', thisTooltip).text($('input.text', thisRow).val());
						thisTooltip.show().css('margin-left', '-'+(thisTooltip.width()/2)+'px');
 
						var validationInput =  $('input.em_sq_validation', thisRow);
						$(validationInput).val($('input.text', thisRow).val())
						fixnum_checkconditions($(validationInput).attr('value'), $(validationInput).attr('name'), $(validationInput).attr('type'));
					}
				});
				$(higherSliders).each(function(i) {
					var thisIndexNum = $(this).attr('data-slider-index');
					var newSliderVal = sliderVal+(thisIndexNum-movedIndexNum);
					if($(this).bootstrapSlider('getValue') < newSliderVal) {
						var thisRow = $(this).closest('.question-item');
						var thisTooltip = $('.tooltip', thisRow);
						$(this).bootstrapSlider('setValue', newSliderVal);
						$('.tooltip-inner', thisTooltip).text($('input.text', thisRow).val());
						thisTooltip.show().css('margin-left', '-'+(thisTooltip.width()/2)+'px');
 
						var validationInput =  $('input.em_sq_validation', thisRow);
						$(validationInput).val($('input.text', thisRow).val())
						fixnum_checkconditions($(validationInput).attr('value'), $(validationInput).attr('name'), $(validationInput).attr('type'));
					}
				});
			}
 
			// Listener on resizing (override the bootstrap callout behaviour)
			$(window).resize(function() {
				setTimeout(function() {	
					$('input[type=text]', thisQuestion).each(function(i) {
						if($(this).val() != '') {
							var thisRow = $(this).closest('.question-item');
							var thisTooltip = $('.tooltip', thisRow);
							$('.tooltip-inner', thisTooltip).text($.trim($(this).val()));
							thisTooltip.show().css('margin-left', '-'+(thisTooltip.width()/2)+'px');
						}
					});
				}, 1);
			});
		});	
	};
})( jQuery );

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: Payek

Please Log in to join the conversation.

More
1 month 3 weeks ago #158169 by Payek
Payek replied the topic: Equation in multiple numercial inputs
Big Thank You jelo and Tony Partner for quick response and help. Now "Van Westendorp Pricing" working perfectly (for me). IMHO this forum&community are the biggest advantages of Lime.

Please Log in to join the conversation.

More
1 month 3 weeks ago #158213 by DenisChenu
DenisChenu replied the topic: Equation in multiple numercial inputs

tpartner wrote: Bug found and fixed - I have updated the Workarounds section - manual.limesurvey.org/Workarounds:_Manip...ascript#Version_2.5x

This is the new code for template.js

If you think it can be interesting and if you are interested, i'm happy to create a new question advanced settings (QuestionAttribute) in plugin to add this script for slider :)

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .

Please Log in to join the conversation.

More
1 month 3 weeks ago #158220 by tpartner
tpartner replied the topic: Equation in multiple numercial inputs
@DenisChenu, I will be creating and contributing a custom question for this. I think this is a perfect application for the new custom question types in 3.x.

Having said that, if you think it also should be in a plugin, feel free to use the code.

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

More
1 month 3 weeks ago - 1 month 3 weeks ago #158223 by DenisChenu
DenisChenu replied the topic: Equation in multiple numercial inputs
My point of view about custom question (QuestionType) and new question settings (QuestionAttribute)

QuestionType are show in the 1st selector : major difference between 2 questionType (in HTML, maybe in column in DB etc …)
QuestionAttribute add a functionnality to a QuestionType (restriction via EM,JavaScript if available)

For example :
- slider can be a QuestionType
- slider reset : clearly a QuestionAttribute
- this script can be a QuestionAttribute
Another
- Map must be a QuestionType
- min_value or max_caracter must be QuestionAttribute
Another with ranking (just a new idea)
- Ranking Question type produce the actual without the doDragDropRank function
- doDragDropRank is a QuestionAttribute with 4 parameters : 1 for use + the 3 current one; coming from core but can be disabled by another QuestionAttribute by an external dev (why not something looking like select2 tagging for example)

Currently if we add a new QuestionType for each script/extra functionnality : it's make harder for Survey Admin to know the best one for his situation (big list …)
The script are really near slider question type => Use slider QuestionType

I don't think we remove QuestionAttribute system, maybe way to add it in QuestionAttribute from core update but not the settings :).
And current system already to add some script with params (see framagit.org/SondagePro-LimeSurvey-plugin/altExcludeMultiple for an example).

:)

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .
Last Edit: 1 month 3 weeks ago by DenisChenu. Reason: Add ranking example

Please Log in to join the conversation.

More
1 month 3 weeks ago - 1 month 3 weeks ago #158225 by tpartner
tpartner replied the topic: Equation in multiple numercial inputs
Sorry, but I cannot agree. I think this, and most alternate question views, should be custom question types, not plugins. They are, after all, questions.

More info for those unaware of this new capability coming in 3.x - github.com/LimeSurvey/LimeSurvey/tree/de...p/question_templates

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last Edit: 1 month 3 weeks ago by tpartner.

Please Log in to join the conversation.

More
1 month 3 weeks ago #158228 by DenisChenu
DenisChenu replied the topic: Equation in multiple numercial inputs
But here : visually (views) it's a slider ? With extra functionnality. No ?
Then :
1. Move slider to own question type (or template, but i like if Survey Admin can choose slider as Question Type)
2. Add settings for the slider

Maybe i didn't look at code clearly, but visually this screenshot seems clearly like a slider.

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .

Please Log in to join the conversation.

More
1 month 3 weeks ago - 1 month 3 weeks ago #158231 by tpartner
tpartner replied the topic: Equation in multiple numercial inputs
Yes, it is sliders. Perhaps I should have said "I think this, and most alternate question views/behaviours, should be custom question types, not plugins.".


...just my point of view...:)

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last Edit: 1 month 3 weeks ago by tpartner.

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now