I’m having trouble summing text values inside of a repeater. I can easily sum values outside of a repeater but am having trouble with it being inside one. Below is my current code. Both text 14 and 45 are inside the same container.
export function dropdownfilter_change ( event , $item ) {
$item ( ‘#text46’ ). text = String ( Number ( $w ( ‘#text45’ ). text ) + Number ( $w ( ‘#text14’ ). text ));
}
when I run this code text46 turns into ‘2’ regardless of that text50 or text45 is. In screenshot below text45 = 22.02 and text14=15,41. Most of the tutorials I find are about inputs being added together but this is a text that happens to be a number. Any help or guidance is apreciated!
Hi! Show that #text45 and #text14 are both displaying numerical values. If they contain any non-numeric characters (e.g. $ or ,), the Number() function will not be able to parse them correctly and the result of the sum will be NaN (Not a Number). Use parseFloat() instead of Number() to parse the values of #text45 and #text14. parseFloat() is a more lenient function and can handle strings with non-numeric characters (e.g. $22.02 or 15,41). If #text45 and #text14 are both within a repeater, you may need to use the getCurrentItem() function to access their values.
I’ve taken the text out of the repeater just to see if I can work around it and am encountering a weird timing issue. Essentially the text14 in the below code only updates after a second change of dropdown1?
Dropdown1 is connected to a database and text7/text12 are connected to the same database. On first change of dropdown1 text7/12 are updated but the value for text14 updates to the default values of text7/12
On a second change of dropdown1 obviously text7/text12 update but now text14 shows the proper addition to above screenshot text7/12 (13.21+23.5=36.71)
Is the issue because I’m linking text7/12 and dropdown1 to a database without code and text14 is linked with code? if that’s not the issue then how do I perform the addition before the database link updates? I would assume some sort of onready function but am doubtful
–Edit–
The above has been solved by adding a settimeout delay for example below
export async function dropdown1_change ( event ){
setTimeout ( function () {
$w ( ‘#text14’ ). text = String ( parseFloat ( $w ( ‘#text7’ ). text ) + parseFloat ( $w ( ‘#text12’ ). text ));
}, 700 );
}s