Welcome, Guest
Username: Password: Remember me

TOPIC: Display commas in long numeric inputs

Display commas in long numeric inputs 3 years 9 months ago #69417

  • Fred
  • Fred's Avatar
  • Offline
  • Gold Lime
  • Posts: 163
  • Thank you received: 5
  • Karma: 3
Is there some way I can raise Tony's karma to 1,000,000? ;)
The administrator has disabled public write access.

Display commas in long numeric inputs 3 years 9 months ago #69514

  • Mazi
  • Mazi's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5725
  • Thank you received: 334
  • Karma: 255
Fred wrote:
Is there some way I can raise Tony's karma to 1,000,000? ;)
Have a look at buddybeers.com/en

;-)

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

Display commas in long numeric inputs 3 years 9 months ago #69692

  • Fred
  • Fred's Avatar
  • Offline
  • Gold Lime
  • Posts: 163
  • Thank you received: 5
  • Karma: 3
Great idea. What's your favorite watering hole Tony?
The administrator has disabled public write access.

Display commas in long numeric inputs 3 years 9 months ago #69697

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5101
  • Thank you received: 1048
  • Karma: 440
Thanks very much for the offer but the nearest participating bar is 893.87 kilometres from here :)

Maybe a donation or other contribution to the project...
Cheers,
Tony Partner

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

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Display commas in long numeric inputs 3 years 9 months ago #69698

  • holch
  • holch's Avatar
  • Online
  • LimeSurvey Team
  • Posts: 3710
  • Thank you received: 501
  • Karma: 163
Hahahah, great idea, but looking at the bars in Northern America, they are quite rare.

And there is basically none in Canada. So this will become difficult. ;-)
Have a look at the manual! It is a really valuable source for information. Here some helpful links:
Manual (EN) | Question Types | Question Attributes | Workarounds

If you found this answer helpful and it saved you some time please consider a donation to the project to keep Limesurvey going!
The administrator has disabled public write access.

Display commas in long numeric inputs 1 week 14 hours ago #124142

  • mas_carpone
  • mas_carpone's Avatar
  • Offline
  • Expert Lime
  • Posts: 157
  • Thank you received: 8
  • Karma: 2
Hi Folks!

Are those workarounds still up to date - or is there something else I should consider to that end?

Thanks!
The administrator has disabled public write access.

Display commas in long numeric inputs 11 hours 39 minutes ago #124474

  • mas_carpone
  • mas_carpone's Avatar
  • Offline
  • Expert Lime
  • Posts: 157
  • Thank you received: 8
  • Karma: 2
Hi Folks!

So here we are: we have worked our way along the hints provided here and got some success... and faced some issues:

First problem is that when a respondant uses the Tab to move to the next question (or cell in an array type question) the format of the number disappears.

Second problem relates to the "totals of rows and columns" that are automatically calculated: they just seem to go mental when the mask is applied (numbers with decimals are produced, etc.)

I have attached the test question in case that can help (haven't attached the template - let me know if that is needed)

Thanks to anyone who may help with this!
Attachments:
The administrator has disabled public write access.

Display commas in long numeric inputs 5 hours 45 minutes ago #124489

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5101
  • Thank you received: 1048
  • Karma: 440
I suspect the problem is that the mask script is interfering with the LimeSurvey "numeric only" function.

I have recently had good success with RobinHerbots' jquery.inputmask, so I would...

1) Remove the "numeric only" and "totals" settings from the question.

2) Download the zip file and place these files in your template directory:
- inputmask.js
- inputmask.numeric.extensions.js
- jquery.inputmask.js

3) Add this to startpage.pstpl after the {TEMPLATEJS} tag:
<script type="text/javascript" src="{TEMPLATEURL}inputmask.js"></script>
<script type="text/javascript" src="{TEMPLATEURL}jquery.inputmask.js"></script>
<script type="text/javascript" src="{TEMPLATEURL}inputmask.numeric.extensions.js"></script>

4) Add a script like something like this to the source of the array (I think the comments describe what is going on).
<script type="text/javascript" charset="utf-8">		
	$(document).ready(function() {	
 
		// Identify this question
		var thisQuestion = $('#question{QID}');
 
		// Insert column "Total" indicators
		$('table.subquestions-list colgroup', thisQuestion).append('<col />');
		$('table.subquestions-list tbody', thisQuestion).append('<tr class="total"><th class="answertext">Total</th></tr>');
		$('table.subquestions-list tbody tr:eq(0) td', thisQuestion).each(function(i) {
			$('table.subquestions-list tbody tr.total', thisQuestion).append('<td class="total information-item"><input type="text" class="column-total disabled" size="20" disabled="disabled" /></td>');
		});
 
		// Insert row "Total" indicators
		$('table.subquestions-list thead tr', thisQuestion).append('<th class="total">Total</th>');
		$('table.subquestions-list tbody tr', thisQuestion).each(function(i) {
			$(this).append('<td class="total"><input type="text" class="row-total disabled" disabled="disabled" size="20" /></td>');
		});
 
		// Clean up the column widths
		var labelWidth = $('table.subquestions-list thead td:eq(0)', thisQuestion).attr('width').replace(/%/, '');
		var answersWidth = (100-labelWidth)/$('table.subquestions-list thead th', thisQuestion).length;
		$('col', thisQuestion).removeAttr('width').css('width', 'auto');
		$('table.subquestions-list', thisQuestion).css('width', '100%');
		$('table.subquestions-list thead  td:eq(0)', thisQuestion).removeAttr('width').css('width', labelWidth+'%');
		$('table.subquestions-list thead th', thisQuestion).removeAttr('width').css('width', answersWidth+'%');
		$('table.subquestions-list input[type="text"]', thisQuestion).css('width', '95%');
 
		// Assign column-specific classes
		$('table.subquestions-list tr', thisQuestion).each(function(i){
			$('> *', this).each(function(i){
				$(this).addClass('column-'+i+'');
				$(this).attr('data-column', i);
			});
		});		
 
		// Place an "Integer" mask on the inputs
		$('table.subquestions-list input[type="text"]', thisQuestion).inputmask('integer', { 
			autoGroup: true, 
			groupSeparator: ",", 
			groupSize: 3,
			'oncomplete': function(){ 
				totalColumn($(this).closest('td').attr('data-column')); 
				totalRow($(this).closest('tr'));
			},
			allowMinus: false,
			allowPlus: false, 
			'min': 0,
			autoUnmask: true,
			removeMaskOnSubmit: true
		});
 
		// Initial values	
		$('table.subquestions-list tbody tr.subquestion-list', thisQuestion).each(function(i) {
			totalRow($(this));
		});		
		$('table.subquestions-list tbody tr:eq(0) td.answer-item', thisQuestion).each(function(i) {
			totalColumn($(this).attr('data-column'));
		});	
 
		// A function to total a row
		function totalRow(row) {
			var thisRowTotal = 0;
			$('td.answer-item input[type="text"]', row).each(function(i){
				thisRowTotal = thisRowTotal + Number($(this).val());
			});
			$('td.total input[type="text"]', row).val(thisRowTotal);
			var rowsTotal = 0;
			$('tr.subquestion-list input.row-total', thisQuestion).each(function(i){
				rowsTotal = rowsTotal + Number($(this).val());
			});
			$('tr.total input.row-total', thisQuestion).val(rowsTotal);			
		}
 
		// A function to total a column
		function totalColumn(column) {
			var thisColTotal = 0;
			$('td.answer-item[data-column="'+column+'"] input[type="text"]', thisQuestion).each(function(i){
				thisColTotal = thisColTotal + Number($(this).val());
			});
			$('td.total[data-column="'+column+'"] input[type="text"]', thisQuestion).val(thisColTotal);			
		}
    });
</script>

If you want the commas in your data, change this:
removeMaskOnSubmit: true
To:
removeMaskOnSubmit: false

Sample template attached (install before survey):

File Attachment:

File Name: Demo_jquer...mask.zip
File Size:120 KB


Sample survey attached:

File Attachment:

File Name: limesurvey...7826.lss
File Size:30 KB

This message has attachments files.
Please log in or register to see it.

Cheers,
Tony Partner

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

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.175 seconds