Please I am using formio to create a form, within the form two fields (currency) are to be added and a total is to be generated in a field called total.
I have tried adding this custom javascript code in the calculated value section to the total field
value= data.value1 + data.value2;
I also tried value = parseInt(data.value1) + parseInt(data.value2);
I have run into this issue before. For some reason, setting the value does not display it in the field itself. What worked for me was using calculateValue
by editing the JSON for the field. To do this:
Add the following code to add the values from the previous fields, where num1
and num2
are your unique keys:
"calculateValue": {
"+": [
{
"var": "data.num1"
},
{
"var": "data.num2"
}
]
}
References:
https://formio.github.io/formio.js/app/examples/calculated.html