Welcome, Guest
Username: Password: Remember me

TOPIC: Display commas in long numeric inputs

Display commas in long numeric inputs 4 years 3 months ago #67709

  • Fred
  • Fred's Avatar
  • Offline
  • Gold Lime
  • Posts: 163
  • Thank you received: 5
  • Karma: 3
We ask a lot of numeric questions where the answer will be in the millions. When a respondent enters this in a numeric field, it looks like this: 200000000. It's hard at a glance to tell if that's 20m or 200m, resulting in input errors. Is there a way to make these entries display with comma separators, like this: 200,000,000 ?
The administrator has disabled public write access.

Display commas in long numeric inputs 4 years 3 months ago #67724

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • Moderator Lime
  • Posts: 8252
  • Thank you received: 1126
  • Karma: 336
Hello,

For this problem, i use extra jquery script with text question.

Jquery masked input for example

ANd see:
Workarounds: Manipulating a survey at runtime using Javascript

Denis
The administrator has disabled public write access.

Display commas in long numeric inputs 4 years 3 months ago #67758

  • Mazi
  • Mazi's Avatar
  • Online
  • LimeSurvey Team
  • Posts: 5843
  • Thank you received: 348
  • Karma: 261
I think there is a nice jQuery plugin for this, see docs.limesurvey.org/Workarounds%3A+Manip...vey#Text_input_masks

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 4 years 3 months ago #67827

  • Fred
  • Fred's Avatar
  • Offline
  • Gold Lime
  • Posts: 163
  • Thank you received: 5
  • Karma: 3
Shnoulle and Mazi, thank you!! Now I see that in the workarounds section. I will try the 2JavaScript options and see which one I can get to work.
The administrator has disabled public write access.

Display commas in long numeric inputs 4 years 3 months ago #67867

  • Mazi
  • Mazi's Avatar
  • Online
  • LimeSurvey Team
  • Posts: 5843
  • Thank you received: 348
  • Karma: 261
You're welcome!

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 4 years 3 months ago #68450

  • Fred
  • Fred's Avatar
  • Offline
  • Gold Lime
  • Posts: 163
  • Thank you received: 5
  • Karma: 3
Hi, reporting back on my test.

1) The Digital Bush Masked Input scripts don't support this application. It's designed for fixed input masks. So you could have a mask "999,999" and it would work correctly if the user input was 100000 (100,000). But if the user entered 10000, it would display as "100,00." I checked this with Josh Bush and he agreed.

2) The Meio mask scripts has a "reverse" parameter that seems to solve the problem. This mask works for all numbers up to 9 billion+.
customMaskThousands:{mask: '999,999,999,9', type : 'reverse', defaultValue : '000'}

However, I saw some warnings in the Workarounds page that the Meio scripts aren't supported anymore? Is it just because of an IE6 problem? (in which case I don't care). Does the suggestion of copying the whole script into the help text work?
docs.limesurvey.org/Workarounds%3A+Manip...vey#Text_input_masks
The administrator has disabled public write access.

Display commas in long numeric inputs 4 years 3 months ago #68451

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5428
  • Thank you received: 1156
  • Karma: 480
I believe that "Meio scripts aren't supported anymore" just means that there is no more development or support so they may not work with future JavaScript libraries. I use the mask plugin extensively and have not had a problem.
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 4 years 3 months ago #68467

  • Fred
  • Fred's Avatar
  • Offline
  • Gold Lime
  • Posts: 163
  • Thank you received: 5
  • Karma: 3
Ok, thank you.

One thing I have realized is that the Meio scripts work great for displaying the numbers with comma separators, but when the data is saved to the database, it's not correct.

For example...
user enters: 10000000
masked input displays: 10,000,000
database stores: 10

In this case I have the mask on a numeric question type. Presumably I could make it work by using a text question type, but this will create problems in the tabulation and analysis.

I just want it to display nicely in the form, but lose the commas when it saves to the database.
The administrator has disabled public write access.

Display commas in long numeric inputs 4 years 3 months ago #68469

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5428
  • Thank you received: 1156
  • Karma: 480
What have you set as the decimal separator?

Survey properties --> Edit text elements
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 4 years 3 months ago #68470

  • Fred
  • Fred's Avatar
  • Offline
  • Gold Lime
  • Posts: 163
  • Thank you received: 5
  • Karma: 3
Hi, I have "Dot(.)" as the decimal separator. I assume this means the real decimal separator (e.g., 3.1415) as opposed to the comma separator for thousands. We are thinking in U.S. style where the decimal separator is "." and thousands are separated by ","
The administrator has disabled public write access.

Display commas in long numeric inputs 4 years 3 months ago #68478

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5428
  • Thank you received: 1156
  • Karma: 480
Hmm...I'm not sure what is going on - I've never run across that problem and the workaround Demo is recording correct values using this mask and the separator set to"." as your's is:
customMask2:{mask: '99.999,9', type : 'reverse', defaultValue : '000'}

However, here is a workaround for the workaround - add a function to remove the commas before the page submits.

Add the following script to the end of template.js. It will interrupt the Next/Submit function and remove all commas from numeric and multi-numeric inputs.
 
	$(document).ready(function() {
 
		// Interrupt next/submit function 
		$('#movenextbtn, #movesubmitbtn').click(function(){
 
			$('.numeric input.text, .numeric-multi input.text').each(function(){
				$(this).val($(this).val().replace(/,/g,''));
			});
 
			return true;
		});
 
	});
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.
Last Edit: 4 years 3 months ago by tpartner.
The administrator has disabled public write access.

Display commas in long numeric inputs 4 years 3 months ago #68605

  • Mazi
  • Mazi's Avatar
  • Online
  • LimeSurvey Team
  • Posts: 5843
  • Thank you received: 348
  • Karma: 261
Does the above solution solve your problem?

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 4 years 3 months ago #68624

  • Fred
  • Fred's Avatar
  • Offline
  • Gold Lime
  • Posts: 163
  • Thank you received: 5
  • Karma: 3
Hi Mazi and Tony. I came in yesterday and spent some more time on this. Unfortunately it still didn't work. I appreciate all your ideas though!!

I thought it might be my template or my survey, so I made a copy of the default template, imported the Sample LimeSurvey Survey for v1.9, and then set up the mask on the first numeric question (first question in the second group.)

Mask: customMaskThousands:{mask: '.999,999,999,9', type : 'reverse'} // I didn't want a default value so I removed.

Decimal separator: Dot (.)

Here is how it handles different numeric inputs:

Enter -> Displays -> Stores in Database
9 -> 9. -> 9
99 -> 99. -> 99
999 -> 999. -> 999
9999 -> 9,999. -> 9.999
99999 -> 99,999. -> 99.999
999999 -> 999,999 -> 999.999
9999999 -> 9,999,999 -> 9.999

It doesn't seem to make any difference whether the additional workaround script is included in template.js.

Note, I am a javascript novice so if it's beyond cutting and pasting then I need to go read a js book. I wonder if input masks are the sort of thing the new Expression Manager will help out with. Interestingly, I notice Survey Monkey seems to have the same problem with large numbers.

Maybe there is something about my setup that is interfering.

Fred
The administrator has disabled public write access.

Display commas in long numeric inputs 4 years 3 months ago #68638

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5428
  • Thank you received: 1156
  • Karma: 480
Did you add my fix to remove the commas?
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 4 years 3 months ago #68654

  • Fred
  • Fred's Avatar
  • Offline
  • Gold Lime
  • Posts: 163
  • Thank you received: 5
  • Karma: 3
Yes, I put the comma-removing script in the template.js

One interesting thing on the LS Sample Survey using the default template: It does seem to take the commas out and save the number correctly when you press Next and go to the next screen, and the data in the database is correct. But if you save it, then use the previous button to go back a page, then next to go forward to the original page, it truncates it and you end up with only the first few digits. Maybe that's because the interrupt is only doing #movenextbtn, #movesubmitbtn? Should I add the previous and resume later buttons to it?

Fred
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.179 seconds