Allow 2 decimals when adding a balance #614
Reference in New Issue
Block a user
Delete Branch "pieterbeulque/fix-613"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Fixes #613
This should fix money fields throughout the app.
One thing I'm not sure of is that not all currencies allow decimals, so this should maybe be dynamic based on the currency this input is in? Maybe that's a property on that
Money.new(0, money&.currency || Money.default_currency)line too?@@ -39,2 +39,3 @@placeholder: Money.new(0, money&.currency || Money.default_currency).formatplaceholder: Money.new(0, money&.currency || Money.default_currency).format,step: "0.01" # Not all currencies have 2 decimal places}RE dynamically setting based on currency:
That's a good point and I'm wondering if we add an instance method in
Money::Currency:And then use it here:
@@ -39,2 +39,3 @@placeholder: Money.new(0, money&.currency || Money.default_currency).formatplaceholder: Money.new(0, money&.currency || Money.default_currency).format,step: "0.01" # Not all currencies have 2 decimal places}I'm just curious how that will behave when you change the dropdown value? If the default currency is EUR or USD it will be set to
0.01, but if you change that dropdown value to JPY, it won't auto-update the money field, right? Do we need to add in some JS to handle that on change?@@ -39,2 +39,3 @@placeholder: Money.new(0, money&.currency || Money.default_currency).formatplaceholder: Money.new(0, money&.currency || Money.default_currency).format,step: "0.01" # Not all currencies have 2 decimal places}Good point, wasn't thinking about that. I think your solution works for the time being, so I'll merge this and I just opened up #625 to capture this additional requirement.
@@ -39,2 +39,3 @@placeholder: Money.new(0, money&.currency || Money.default_currency).formatplaceholder: Money.new(0, money&.currency || Money.default_currency).format,step: "0.01" # Not all currencies have 2 decimal places}Sweet, cheers. Curious to learn what'd be the modern Rails way to do this.
@@ -39,2 +39,3 @@placeholder: Money.new(0, money&.currency || Money.default_currency).formatplaceholder: Money.new(0, money&.currency || Money.default_currency).format,step: "0.01" # Not all currencies have 2 decimal places}Same, adding a JS controller just for this seems overkill, but I can't think of any other solution myself