It doesn't make sense to use a text field for a float. With the numeric entry, you can verify that the number entered is within certain bounds, that it is in fact a number, and it has an onActionPerformed event that can be triggered from direct, protected, or button modes.
The onBlur event does not guarantee that the user is finished editing the field.
How are you going to compare a kW setting or reading with a database string? Keep the value and units separate in the database and in the user interface.
The print in the except should have told you what went wrong. It should be printing something along the lines of "ValueError: Can't convert string to float".
Also, why an onBlur event ? Just put a button to validate the value. I would hate to have a value sent to a database just because I clicked outside of a field. Particularly if there's a confirmation popup !
Ok, thanks everibody, finally I used a Numeric Field with an onActionPerformed as @dkhayes117 suggested with this script:
def runAction(self, event):
import sys
import traceback
tr
new_kwlim_raw = self.props.value
codigo = self.getSibling("codigo").props.text.strip()
new_kwlim = float(new_kwlim_raw) if new_kwlim_raw is not None else 0
system.perspective.print("Actualizando KWLIM a {} para {}".format(new_kwlim, codigo))
system.db.runPrepUpdate(
"UPDATE T_SEDE SET KWLIM = ? WHERE CODIGO = ?",
[new_kwlim, codigo],
"PSS"
)
system.perspective.openPopup(
id="success-popup",
view="Page/Aprobar",
params={"codigo": codigo, "kwlim": new_kwlim},
title="Updated Successfully!",
modal=True,
width=400,
height=40
)
except Exception:
exc_type, exc_value, exc_tb = sys.exc_info()
error_details = traceback.format_exception(exc_type, exc_value, exc_tb)
for line in error_details:
system.perspective.print(line)
system.perspective.openPopup(
id="error-popup",
view="Page/ErrorPopup",
params={"message": "Failed to update. See console for details."},
title="Error",
modal=True,
width=400,
height=100
)
and it´s working fine. @Transistor I will show the units apart on a label, they don´t come from the DB I just added them and @pascal.fragnoud I will work on the interface so it´s clear the user is changing some value on the database and doesn´t cause trouble.