Closed (duplicate)
Project:
Webform Calculator
Version:
7.x-2.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
12 Oct 2014 at 01:42 UTC
Updated:
5 May 2016 at 11:56 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
kyleheney commentedHi,
I would also like to see this type of functionality. I am using the Formula field on an invoice and the result is only one decimal place (or no decimal places for whole numbers). It looks "off" when a total dollar amount only has one decimal place.
I think this is actually an issue with the module because a user can choose the "Precision" of the formula, but that only acts as a "limit" and not as a default view. It would be better if the "Precision" field would add a zero for any significant digits that don't "exist".
Comment #2
Katy Jockelson commentedI agree that it would be great to change the format of what shows when you have selected 2 in the precision dropdown.
i.e 8 should render as 8.00 and 4.5 should be 4.50.
Any chance of implementing this?
Comment #3
kruser commentedI imagine it should have the same options as a Number field (since it's calculations are based on them), ex prefixes, decimal places, thousands seperator, etc.
I'm totaling up dollar amounts and need a formatted total.
Comment #4
rafalenden commentedComment #5
kyleheney commentedHi,
Any update on this issue? I've created several more forms, but the totals look very unprofessional because they are dollar amounts that sometimes only have 1 decimal place.
Thanks
Comment #6
rafalenden commentedHi kyleheney,
at the moment I'm busy with other stuff, however any patches are welcome.
Comment #7
kyleheney commentedOkay, I've been able to format the formula result so that it displays 2 decimal places on the form itself (in "real-time")
Issue now is that the Submission results do not use the same formatting. They are still showing the improper formatting.
Here's what I've done so far:
Add this code webform_calculator.js (I put it just above the Round section near the end; line 138ish)
Then on line 110, change
formulaResult = Drupal.webformCalculator.round(formulaResult, formulaComponent.extra.precision);to
formulaResult = Drupal.webformCalculator.precision(formulaResult, formulaComponent.extra.precision);This works to change the format on the form from, for example, "5" to "5.00". On the submission results pages though, the format is still "5".
Any guidance/ideas to move this formatting over into the results?
Edit: I realize this "solution" does not provide an option for setting the precision, but this is how I would use this module, so I didn't take that into consideration. I don't think this would ever get pushed as a committed option for the module, as it doesn't give full functionality, but I'd still like to come up with a solution for my use case so that others can choose to implement it if they are using the formula fields in a similar way.
Comment #8
capmex commentedTo display two decimal places is easier to change the following line on webform_calculator.js:
formulaComponentElement.text(formulaResult);to
formulaComponentElement.text(formulaResult.toFixed(2));Comment #9
kyleheney commentedThe suggestion in #8 does not work. No change is observed after making this change. The result of the formula still does not show two decimal places on the Webform Results pages.
Comment #10
kyleheney commentedI think the solution lies somewhere outside the webform_calculator.js file.... any edits I make to the JS file are only affecting the form elements prior to submission. Once submitted, the values are "static" and do not format correctly (50.00 on the form will show as 50 in submission results).
Is there any way to target the submission results to make sure they should the same precision? It doesn't make sense that I can set the precision of the formula on the form, but the results don't respect this choice of precision.
Comment #11
joel_osc commentedHere is a patch that adds the decimal, point, separator and exclude zero configuration to the formula component. I have also added a call in the theme function to _webform_number_format() which handles formatting the number according to the configs.
@kyleheney - would it be possible for you to look at the JS and integrate these configs into the JS code so that webform form render follows the same logic?
Comment #12
kyleheney commentedI can confirm this patch works and adds the necessary decimal and zeros when desired. THANK YOU
@joel_osc I'm not sure what is required in the JS code. I added some code in #7 that seems to work well for me. My knowledge of JS is limited and I actually found this example through multiple online searches.
Let me know if there is anything else I can do.
Comment #13
joel_osc commentedI think the JS logic needs to match the logic in the theme code that I wrote. I looked at your JS in #8 and it needs a bit of work. I will have our JS guy take a look at it.
Comment #14
kyleheney commentedI definitely welcome any changes or additions to what I posted. I realize what I provided was a "forced" addition and didn't provide options for the end user, so I can definitely see how it could be improved. Happy again to test any patch that is provided.
Can't wait to see these changes hopefully added to the next release of this module. They're very useful in my opinion.
Comment #15
aastrong commentedHey there, sorry for the long wait, had other things on my plate.
So I was able to get this working by mostly using an existing jquery plugin, and a small bit of basic js.
Please take a look at my patch ( which includes @joel_osc's patch )
I've also included the JS plugin file that I added to do this.
The jquery plugin can also be found here
https://github.com/customd/jquery-number
Results seem to be working and consistent for me.
Comment #16
penone commentedHaving an issue with patch in #15:
I have 3 calculation fields:
1. Subtotal (calculates the weight entered by the price per lb)
2. Tax (calculated by multiplying the subtotal by .16)
3. Total (calculated by adding subtotal + tax.
If my subtotal goes over 999.00 the tax and total no longer calculate.
Not sure why this is doing this. Anyone else running into this?
Comment #17
aastrong commented@penone Hey there, I haven't run into the issue - but I'll try to set up a similar scenario and do some testing in the next few days.
Comment #18
penone commentedSo I believe the problem lies with the comma. If I select "none" as a separator option the word "none" is actually shown in the field. (ex. 2none000.00 for 2000.00).
Not sure how to go about fixing this.
Comment #19
aastrong commentedHey there, sorry im just looking at this now.
The issue was that value none was set to "none' instead of ''
attaching patch again - please lemme know if this works for you.
Cheers.
Comment #20
vladsavitsky commentedThere is working patch which does even more:
https://www.drupal.org/node/2652174
Comment #21
vladsavitsky commented