Check, how the selected value on the Dropdown list was changed

Does anybody know, how to check, how the selected value on the Dropdown list was changed:

  • either with a mouse click on the dropdown list
  • or with binded property ‘Selected Value’

I have a dropdown list with the ‘Selected Value’ property binding to the SQL query.

When the user chooses from the dropdown list, the selected value is written to the database table.
Or when the ‘ident’ and ‘idx’ in the selection query changes, the selected value is populated from a database table.

Now, every time, when the user chooses from the dropdown list, I must log that change into the log db table which means that the user has changed the value

#this is on the propertyChange event of the dropdown list
if event.propertyName == "selectedValue":
	### Recepture AuditLog
	sufix = ""
	lista = [u"ZUNANJE", u"NOTRANJE"]
	staraVrednost = event.oldValue
	staraVrednost = lista[staraVrednost]
	novaVrednost = event.newValue
	novaVrednost = lista[novaVrednost]
	if staraVrednost != novaVrednost:		
		imeRecepture = event.source.parent.parent.parent.getComponent('lstRecepture').ime_recepture
		ident = event.source.parent.parent.parent.getComponent('lstRecepture').ident
		imeParametra = u'vrednost'.upper()
		opisNastavitve = event.source.parent.getComponent('lblOpisNastavitve8').text.upper()
		uporabnik ="[Client]loggedUser").value
		opis = "Polje " + opisNastavitve +  " je bilo spremenjeno iz " + str(staraVrednost) + " na " + str(novaVrednost)
		query = "INSERT INTO recipes_auditlog (ime_recepture, ident, opis, opis_nastavitve, stara_vrednost, nova_vrednost, uporabnik) VALUES (?,?,?,?,?,?,?)"
		system.db.runPrepUpdate(query, [imeRecepture, ident, opis, opisNastavitve + ", " + imeParametra, staraVrednost, novaVrednost, uporabnik])

But the problem is, that the change is also logged when the value is changed by the selected query.

So, how would I distinguish between one change and another?

I generally split the incoming binding to a custom property on the component. Then unidirectionally bind selectedValue from that custom property. (This only works when the incoming binding is not polling.) Incoming changes pass through and update the component, leaving both properties equal. Operator changes leave the incoming binding alone, so the two properties are unequal. You can check equality in your onChange event to skip writing to the DB if it wasn’t the operator.

1 Like

I tried that and it’s working great.
Now on to changing the entire recipe form…

Thank you @pturmel for your suggestion. :+1:

In a form, I instead use inequality to style “dirty” fields, and use a separate button to do all the writes at once. Followed by refreshing the bindings.