I have a good deal of forms with numerical fields that are used to enter rather large numbers. I was using some javascript to automatically place a comma to delimit the number to make it easier to read in the form. The problem is that, when the field is saved to the database, the comma in the text field makes it a non-integer, so it only saves the first set of digits (left to right) before it runs into a comma.
My question is: What is the best way to handle this? I figure it must be a relatively common situation, though I can't really find a simple answer.
I've tried adding a before validation
method to strip out the commas, but at that point, the number has been altered. If I get desperate, I figure I could:
1) Add a dummy field into my view and hide the integer field
or
2) Grab and alter the parameters in my controller
or
3) Override the submit button to run a comma-clensing script prior to submit.
But all of those seem excessive. Any better practices out there for this?
Thanks in advance.