Search code examples
google-app-maker

onValueChange not being activated by a script change on load


Say I have a dropdown with values X, Y, z, and I have a script taht does something to another dropdown when it is modified (this all works by hand).

But now, sometimes the dropdown value is known previously, so instead of having the user choose the number from the dropdown, it is set by the program.

Now the onValueChange() script is NOT being called, so the logic on the rest of the form isn't happening.

The script that runs and changes the values if the properties already exist is happening on the page onAttach().

From reading the descriptions, onValueChange() SHOULD do something here, but it isnt' being triggered, I added a console line to be sure.


Solution

  • Typically there is an execution order with onAttach events, so if you set a function in the page onAttach event that you would expect to cause an onValueChange event in another element within the page, that event may not get executed because at the time the page attaches and the function executes, the other widget may not yet exist in the DOM tree.

    Therefore it is typically better to attach such functions to the individual elements onAttach event vs the page onAttach event.