If you have a form generated by Wappler that has, say, 50 fields and 20 of those are currency input fields that are auto populated depending on selections made by the user, what is the best way to calculate a total and put it in a Totals field ready for inserting into a DB?
I know it is a fairly generic question but was wondering before I build a page.
If the 20 or so input fields are generated by a repeat from a DB, and therefore I don’t know exactly how many fields there are, how can I do a repeat within a variable so I can add up all the totals on the fly?
Neil,
remove the repeat region from this row where it is placed now. id="row_specialist" dmx-repeat:repeat1="sc_specialist_q.data.sa_specialist_q"
Add a repeat children which wraps this row. Then the code i provided will work …
Avoid using just repeat region and use repeat children instead. The repeat children is actually a repeat component in App Connect, the normal repeat is a dynamic attribute. Only component can have properties, data and events - that’s why the calculation code which i provided won’t work with the regular repeat.
Hi @Teodor, one final question on this subject, how can I easily use the selected checkbox ID in the text at the end, I can’t seem to get that to work either
Should it be ‘pushed’ with SetValue when the ‘3’ is clicked or can it be ‘fetched’ by setting some sort of listener? Either way I can’t seem to get the ‘value’ of ‘3’ into an input field or variable.
I am sure this makes sense but I cannot get the various fields to calculate.
The ‘Paint & sundries’ at £88 should be added to the ‘Parts’ at £77. I have done this with
That's because the inputs always return strings. So the string 88 added to the string 77 equals 8877.
You need to convert them to number first, using the toNumber() formatting option.