This topic is locked
[SOLVED]

Calculated Fields on the Fly

5/13/2022 2:55:53 AM
PHPRunner General questions
A
Ace Drummond author

I have some calculated fields that I develop on the fly using Java Script onLoad Event.

The fields are defind in the mysql database as FLOAT field edit/view is view as currency read_only

The calcuations work correctly; however, the results of the calculations when displayed after key_up function is executed do not get formatted as currency.

When I go back to the list or subsequently the edit screen the values are correct values and formatted correctly as currency!

I noticed in your video that the same things happens with the example you show there.

Is there any way to address this so that when the results of the calculation show up they are formatted.

Thanks//

admin 5/13/2022

Since you perform the calculations and update the field value manually you need to add currency formatting manually as well. You need to format your value as a currency after the calculation but before you do setValue();

A
Ace Drummond author 5/19/2022

It took some effort but following your recommendation I got it to work. Thanks for steering me!

Example:

var money = (Number(ctrlCalendarCost.getValue()) * Number(ctrlCalendars.getValue())); <--calculates number of calendars * cost per calendar = cost of calendars.
ctrlCalendarsTotal.setValue(new Intl.NumberFormat('en-US', {style: 'currency', currency: 'USD'}).format(money));<--formats the result 'money' to currency and sets value.

var money = (money + Number(ctrlDues.getValue())); <-- second calculation adds the cost of calendars (calculated above) and adds dues. (note use of variable 'money' in the calculation.
ctrlTotal.setValue(new Intl.NumberFormat('en-US', {style: 'currency', currency: 'USD'}).format(money));<-- formats result of cost of calendars + dues

I did the calculation in to the variable money and then setValue to my control that will be displayed.

In the case of the second control I wanted to display (which used the result of the first calculation as a factor) I had to use the calculated value 'money' in the formula because once I converted it to currency it could not be used in the next calculation as format had changed!

End result it is working now.