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

TOPIC: Array number with Filter option needs one column with formula

Array number with Filter option needs one column with formula 2 years 5 months ago #104251

  • pmp
  • pmp's Avatar
  • Offline
  • Junior Lime
  • Posts: 20
  • Karma: 0
Hello,

I am new to this and found very interesting . I am trying to setup a evaluation survey. I have added two questions. q1 a multiple choice type and second question is Array Numbers with filter condition on Q1.with subquestions Y Scale 3 Sub questions SQ0001-SQ0003 and X scale 5 Sub questions SQ0001 to SQ0005. Now SQ0005 needs to calculate automatically based on the formula. How Can i achieve this. I saw many posting, but i am not sure how to get this done.

Would appreciate any help
Attachments:
The administrator has disabled public write access.

Array number with Filter option needs one column with formula 2 years 5 months ago #104261

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6114
  • Thank you received: 1356
  • Karma: 532
You will need to use JavaScript to automatically load those inputs.

1) Set up your survey to use JavaScript.

2) Add this script to the source of the array.

<script type="text/javascript" charset="utf-8">	
 
	$(document).ready(function(){
		var thisQuestion = $('#question{QID}');
 
		// Add some classes for manipulation
		$('tr.subquestions-list', thisQuestion).each(function(i){
			$('> *', this).each(function(i){
				$(this).addClass('col-'+i+'');
			});
		});
		$('.col-2 input[type="text"]', thisQuestion).addClass('final');
		$('.col-3 input[type="text"]', thisQuestion).addClass('percent');
		$('.col-4 input[type="text"]', thisQuestion).addClass('rating');
 
		// Disable the "Rating" inputs
		$('input.rating', thisQuestion).prop('disabled', true);
 
		// Listeners on the "Final" and "Percent" inputs
		$('input.final, input.percent', thisQuestion).change(function(event) {
			handleRating(this);
		});
		$('input.final, input.percent', thisQuestion).keyup(function(event) {
			handleRating(this);
		});		
		function handleRating(thisInput) {
			var thisRow = $(thisInput).closest('tr.subquestions-list');
			var thisFinal = $('input.final', thisRow).val();
			var thisPercent = $('input.percent', thisRow).val();
			if(thisFinal != '' && thisPercent != '') {
				$('input.rating', thisRow).val(thisFinal * thisPercent / 100)
			}
			else {
				$('input.rating', thisRow).val('');
			}
		}
 
		// Re-enable the "Rating" inputs on submit
		$('form#limesurvey').submit(function(){			
			$('input.rating', thisQuestion).prop('disabled', false);
		});
	});
 
</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.
The following user(s) said Thank You: pmp

Array number with Filter option needs one column with formula 2 years 5 months ago #104304

  • pmp
  • pmp's Avatar
  • Offline
  • Junior Lime
  • Posts: 20
  • Karma: 0
This is sweet. It worked- I couldn't imagine we have such huge possibilities of this tool.
I luv it :cheer:

Thanks a lot for helping me in this
PMP
The administrator has disabled public write access.

Array number with Filter option needs one column with formula 2 years 5 months ago #104310

  • pmp
  • pmp's Avatar
  • Offline
  • Junior Lime
  • Posts: 20
  • Karma: 0
Is there a way I can get the Total of the last column. I am not getting the total option enable as it is array Numbers type.
The administrator has disabled public write access.

Array number with Filter option needs one column with formula 2 years 5 months ago #104317

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6114
  • Thank you received: 1356
  • Karma: 532
Can you provide a screenshot or mockup?
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.

Array number with Filter option needs one column with formula 2 years 5 months ago #104321

  • pmp
  • pmp's Avatar
  • Offline
  • Junior Lime
  • Posts: 20
  • Karma: 0
Attached the mockup-
Appreciate your help-
Attachments:
The administrator has disabled public write access.

Array number with Filter option needs one column with formula 2 years 5 months ago #104323

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6114
  • Thank you received: 1356
  • Karma: 532
Okay, I get it.

Do you need this recorded in the data or is it just a visual for the respondent?


.
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.

Array number with Filter option needs one column with formula 2 years 5 months ago #104328

  • pmp
  • pmp's Avatar
  • Offline
  • Junior Lime
  • Posts: 20
  • Karma: 0
this is to be recorded-
Thanks
The administrator has disabled public write access.

Array number with Filter option needs one column with formula 2 years 5 months ago #104354

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6114
  • Thank you received: 1356
  • Karma: 532
Okay, in that case, I would add another sub-question to the array - "Total".

Then use this script instead of the one above. In addition to previous functionality, it will:
- Hide the first 3 inputs in the "Total" row
- Dynamically load the column totals into the "Total" inputs
<script type="text/javascript" charset="utf-8">	
 
	$(document).ready(function(){
		var thisQuestion = $('#question{QID}');
		var qID = {QID};
 
		// Add some classes for manipulation
		$('tr.subquestions-list', thisQuestion).each(function(i){
			$('> *', this).each(function(i){
				$(this).addClass('col-'+i+'');
			});
		});
		$('tr.subquestions-list:last', thisQuestion).addClass('last');
		$('tr.subquestions-list:not(.last) .col-2 input[type="text"]', thisQuestion).addClass('final');
		$('tr.subquestions-list:not(.last) .col-3 input[type="text"]', thisQuestion).addClass('percent');
		$('tr.subquestions-list:not(.last) .col-4 input[type="text"]', thisQuestion).addClass('rating');
 
		// Disable the "Rating" inputs
		$('input.rating', thisQuestion).prop('disabled', true);
 
		// Hide the unwanted total inputs
		$('tr.subquestions-list.last input[type="text"]:not(:last)', thisQuestion).hide();
 
		// Initial totals
		$('tr.subquestions-list.last input[type="text"]', thisQuestion).val(0).prop('disabled', true);
		var lastRowCode = $('tr.subquestions-list:last', thisQuestion).attr('id').split('X'+qID)[1];
 
		// Listeners on the "Final" and "Percent" inputs
		$('input.final, input.percent', thisQuestion).change(function(event) {
			handleRating(this);
		});
		$('input.final, input.percent', thisQuestion).keyup(function(event) {
			handleRating(this);
		});		
		function handleRating(thisInput) {
			var thisRow = $(thisInput).closest('tr.subquestions-list');
			var thisFinal = $('input.final', thisRow).val();
			var thisPercent = $('input.percent', thisRow).val();
			if(thisFinal != '' && thisPercent != '') {
				$('input.rating', thisRow).val(thisFinal * thisPercent / 100)
			}
			else {
				$('input.rating', thisRow).val('');
			}
		}
 
		// Listeners on the inputs to load totals
		$('tr.subquestions-list:not(.last) input[type="text"]:not(.rating)', thisQuestion).change(function(event) {
			handleTotals();
		});
		$('tr.subquestions-list:not(.last) input[type="text"]:not(.rating)', thisQuestion).keyup(function(event) {
			handleTotals();
		});	
		function handleTotals() {
			$('tr.subquestions-list.last input[type="text"]', thisQuestion).each(function(i) {
				var thisCode = $(this).attr('id').split('X'+qID+lastRowCode+'_')[1];
				var newTotal = 0;
				$('tr.subquestions-list:not(.last) input[type="text"][id$="_'+thisCode+'"]', thisQuestion).each(function(i) {
					if($.isNumeric($(this).val())) {
						newTotal = newTotal + Number($(this).val());
					}
				});
				$(this).val(newTotal);
			});
		}
 
		// Re-enable the "Rating" inputs on submit
		$('form#limesurvey').submit(function(){			
			$('input.rating, tr.subquestions-list.last input[type="text"]', thisQuestion).prop('disabled', false);
		});
	});
 
</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.

Array number with Filter option needs one column with formula 2 years 5 months ago #104356

  • pmp
  • pmp's Avatar
  • Offline
  • Junior Lime
  • Posts: 20
  • Karma: 0
Yesss. It worked.
Thank you verymuch, this is an awsome tool. No doubt.
The administrator has disabled public write access.

Array number with Filter option needs one column with formula 2 years 5 months ago #104855

  • pmp
  • pmp's Avatar
  • Offline
  • Junior Lime
  • Posts: 20
  • Karma: 0
I am just trying to figureout how to add the validation on the 'Self ' column - exepected value between 1 and 5 and the % column totals ( for all the rows) should not exceed 100. I tried giving it in the question validation but it didnt work.

Any help would be highly appreciated.

Thanks
PMP
The administrator has disabled public write access.

Array number with Filter option needs one column with formula 2 years 5 months ago #104881

  • pmp
  • pmp's Avatar
  • Offline
  • Junior Lime
  • Posts: 20
  • Karma: 0
is there a way I can set validation on Self ( each cell) like value should be between 1 to 5 and % total should not be more that 100%?

I tried using the sub question /question validation option and it didnt work. any help would be appreciated
The administrator has disabled public write access.

Array number with Filter option needs one column with formula 2 years 5 months ago #104887

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • Moderator Lime
  • Posts: 9254
  • Thank you received: 1319
  • Karma: 382
Hi,

Question validation equation : sum(self)<100
Question validation tip : Not more than 100% (actual {sum(self)}%
Sub-question validation equation : this>=1 and this<=5
Sub-question validation tip : Each answer must be between 1 and 5

Something like that ?

Denis
Assistance on LimeSurvey forum and LimeSurvey core developpement are on my free time (Say thanks ?).
A bug not reported is a bug not corrected. | Please, read the documentation | La doc en français à besoin de vous
The administrator has disabled public write access.

Array number with Filter option needs one column with formula 2 years 4 months ago #106441

  • pmp
  • pmp's Avatar
  • Offline
  • Junior Lime
  • Posts: 20
  • Karma: 0
Can somebody help to resolve this.

I have a Array Number. What I need is one column will have predefined values ( read only mode).
and the next two columns input should validate based on this read only column value.
Also final total at the end for the two input columns.

I used some sample code give earlied and tried to achive, but somehow i am not able to get what i want.

If someone can help me to how to assign values to the particular array column and make read only and also how to use the validation based on the value in there. Attached a screen In this i gave the maximum value in the parenthesis as part of the Y Scale sub questions. Ideally this should have been a seperate read only column with assigned values.

Thanks in advance
Attachments:
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.480 seconds
Imprint                   Data Protection Statement                  Revocation information and revocation form