How to implement 'onChange' but for text/string/number?

I currently have a #dropdown1 which people can select an option from. Once they select an option a #text1 updates a number (These updates are linked via dataset without code) and adds to #text2 and the function ‘addition’ is performed which subsequently updates another #text3 number.

The issue I’m having is that the timing of the dropdown updating text1 seems to have a slight delay sometimes. I got around this delay by adding a setTimeout to performing the function, however, sometimes the delay is more than 700 below. This is an issue because if it takes less than 700 the function will still wait for 700 which is annoying.

With the dropdown1 and text1 being linked via dataset without code I am stuck unsure how to perform a sort of text1 onchange? Below is my code

async function addition ( ) {
$w ( ‘#text3’ ). text = (( parseFloat ( $w ( ‘#text1’ ). text ) + parseFloat ( $w ( ‘#text2’ ). text ))). toFixed ( 2 ). toString ();
}

export async function dropdown1_change ( event ){
setTimeout ( function () {
addition ();
}, 7 00 );
}

I tried experimenting with onChangeText but can’t seem to figure it o ut as I keep getting
“Property ‘onChangeText’ does not exist on type ‘string’.” or
"Property ‘onChangeText’ does not exist on type ‘number’.
and I can’t seem to figure out how to update text3 into a text?

  1. Why your functions are both → ASYNCHRONOUS, although you do not use any ASYNCHRONITY inside these functions ???

  2. Instead of using EXPORT-FUNCTIONS, try to implement all your CODE into just one BIG-CODE-BLOCK.

  3. Try to work more with CONSOLE !!! THis will help you to understand and to DEBUG your own CODE.

What do you get for…

(parseFloat($w('#text1').text)

…as resullt ??? CHECK IT …

console.log(parseFloat($w('#text1').text));
  1. How to turn a STRING into —> NUMBER ?
let myNumber = Number(myString);
  1. How to turn a Number into —> STRING ?
	let myString = String(myNumber);

The async may be remnants from when the code was quite different. I will delete it now.

I’m using export functions because I call the function ‘addition’ multiple times in other parts of the code that I didn’t include in this post

I don’t seem to be having any issue with turning the number into a string, The problems seem to arrive with the fact that onChange only applies to input elements and not things like text/string/number blocks. Do you have any suggestions on how to perform an onChange on a text/number/string item (not input or dropdown)?

Your problem is like in many other different situations, that you are mixing DATASET-Connections+Property-Panel and in parallel try to CODE additional features.

This way is possible, but you have to pay attention that a connected DATASET-VERSION will have it’s own process-cycle and timings.

And here you have exactly the mentioned case.

With the dropdown1 and text1 being linked via dataset without code I am stuck unsure how to perform a sort of text1 onchange ? Below is my code.

CODE vs. DATASET-CONNECTIONS + USED OPTIONS INSIDE OF PROPERTY-PANEL.

Always the same…:unamused:

Your possibilities…

  1. Use just coded-version, disconnecting all your elements from your dataset and doing all connections between DATASET and ELEMENTS ----> BY CODE ONLY !

  2. You will have to use your already INTEGRATED DELAY-TIMING, because you will have to UPDATE DATA, after the automatic CYCLE of connected DATASET has done it’s job.

In this post here, you will find some kind of a similar problem…
https://www.wix.com/velo/forum/coding-with-velo/opening-links-in-new-tab-by-clicking-button-in-the-repater

Such problems you can find daily here inside of the VELO-FORUM.

I’ve disconnected a lot of the elements but still currently have one or two connected (I don’t think the ones connected will effect the code but i could be wrong.

Now I’ve got the below code but am having a hard time figuring out where to fit the .then. I’ve tried in the onchange and the filter function but can’t seem to figure out the syntax as the code I write always seems to think .then is a function and says “Cannot find name ‘then’. Declaration or statement expected.”

function addition ( ) {
$w ( ‘#F1’ ). text = (( parseFloat ( $w ( ‘#1’ ). text ) + parseFloat ( $w ( ‘#11’ ). text ) )). toFixed ( 2 ). toString ();
}

function filter ( title , continent ) {
if ( lastFilterContinent !== continent ) {
let newFilter = wixData . filter ();
if ( continent )
newFilter = newFilter . contains ( ‘title’ , continent );
$w ( ‘#dataset4’ ). setFilter ( newFilter );
lastFilterContinent = continent ;
}
}

export function dropdownfilter_change ( event , $w ) {
filter ( lastFilterContinent , $w ( ‘#dropdownfilter’ ). value );
setTimeout ( function () {
addition ();
}, 800 );
}

For example, I tried something like below but am not sure whats going on.

export function dropdown4_change ( event , $w ) {
filter4 ( row5filter , $w ( ‘#dropdown4’ ). value );
. then (( results ) => {
addition ();
})
}