I want to realise following functionality with a numeric text field:
users should enter an ID ( only digits). After entering an ID, pressing Enter should confirm the input. In the keyPressed event script, I want to display relevant information based on the entered ID. However, I'm facing challenges in retrieving the entered ID and preventing users from entering invalid characters.
I'm not sure I understand what you mean by commit the value, but you can use the keyPressed or keyReleased event handlers to do things on specific keystrokes.
Example:
# Perform a task with text property on enter pressed
if event.keyCode == event.VK_ENTER:
print "Commit '{}' in some way".format(event.source.text)
Result for45678on enter being pressed:
Edit: The formatted text field does have a commitEdit method, so perhaps this would work:
# Commit the edit on enter pressed
if event.keyCode == event.VK_ENTER:
event.source.commitEdit()
Thank you, it works now. If you enter the exact number of digits set in the Formatted Mask Pattern, it automatically commits. When the length is not equal, it adds spaces.