How to ignore propertyChange events until window is loaded

We have a large multipage (tabbed) form which uses client tags to store data until the form is saved. The form is for editing existing data, so the tags are set before the form is opened. This works fine.

This form has a dropdown control that clears/resets a bunch of other input fields if it is changed. This uses the propertyChange event as normal and also works fine.

However, the propertyChange event for the dropdown fires when the form is opened and all the controls are being populated with initial data, resulting in the other fields being reset incorrectly. How can I detect and suppress this?

I tried using system.util.invokeLater, but that does not solve the problem. I’ve seen mention elsewhere on the forum that bindings update outside of the normal event queue so that would make sense.

Any ideas much appreciated.


Are you checking for a specific property on your drop down property change?

If you are just putting your script in the property change then when any property changes on the drop down your script will run.

Usually I am looking at the selectedValue or i will sometimes use the selectedIndex.

if(event.propertyChange == "selectedValue"):
    print "run code"

or if my drop down’s selectedValue is bound to -1 and i do not want the code to run when the screen loads i will do something like this

if(event.propertyChange == "selectedValue" and event.newValue != -1):
    print "run code"


if(event.propertyChange == "selectedIndex" and event.newValue != -1):
    print "run code"

Yes I am filtering by the propertyName.

Unfortunately neither the new value or old value are any help in distinguishing between initialisation and an update as the result of a user action. For example: on form initialisation, the value will be going from “Select One” to whatever the currently saved value is, if that value is set (it might not be). When the user changes the control, it may also be going from “Select One” to the new value.

In any case, even if I could find some workaround for this specific case, I’m encountering this problem in many other places as well. What I need is a way to detect the difference between events triggered by initialisation and events triggered as a result of user interaction.

You are right, you cannot distinguish between user input and initial change in a propertyChange script. In this case I usually put a custom property to the component called firstChange that is a boolean. Make sure the value is false when the window opens for the first time. When the first propertyChange occurs you can do the following:if event.propertyName == "someProperty": if event.source.firstChange == 0: event.source.firstChange = 1 # ignore first change else: # do your code hereHopefully that helps.

Unfortunately the firstChange variable doesn’t help, because the value is not guaranteed to change when the window loads, for example if the value is NULL.

In the end, this turns out to be the same problem is described in this thread, where SQL bindings do not use the normal event system, so invokeLater cannot be used to force code to wait for them to update: viewtopic.php?f=72&t=8923

The solution is to remove the SQL binding and create a function to update the value manually. Then call this function when the window loads and when any dependent properties change, or use a timer for polling. This setup gives full control over updates and events happen in a clearly defined order. From this point it is easy to add a parameter or custom property to detect the difference between a call from visionWindowOpened or elsewhere.