I’m trying to handle the user deleting the value in a numeric entry field. The props.value is bound to a view parameter that comes from a DB query. The value from the DB is usually displayed, but the user can edit the value and a Property Change Script updates the DB with the new value.
What I am running into is if there is a non-zero value and I click on the numeric entry field (whose “mode” is “direct”) and hit the Backspace key and then Enter, my script runs as I expect and a 0 is updated into the DB. But if I use the Delete key instead of the Backspace, the value reverts to the previous value.
This is what the change script looks like (simplified):
newhours = currentValue.value
try:
newhours = float(currentValue.value)
except:
newhours = 0
params = {"hours":newhours}
system.db.runNamedQuery("EditHours",params)
system.perspective.sendMessage("update")
I had also tried:
newhours = currentValue.value
if currentValue.value is None or len(str(currentValue.value)) <= 0:
newhours = 0
params = {"hours":newhours}
system.db.runNamedQuery("EditHours",params)
system.perspective.sendMessage("update")