OnKeyDown event not working

Hi,
We are trying to use the OnKeyDown event to validate a string in a text field but it doesn’t trigger at all.
Is there a bug with this event?
I even tried with a simple script

if len(self.props.text) >= 3:
		self.props.text = "3 chars"

It looks like you’re using Perspective, so I’ll chime in.

The onKeyXXXX Events only execute if the component they are attached to is the component which currently has focus.

For example:

  1. I have a Text Field with a configured onKeyPress Event.
  2. In an active session, I click into the Text Field and press “A”. This will trigger the onKeyXXXX Events as expected.
  3. I then click a button elsewhere on the page, and press Enter. The onKeyXXXX Event will not fire because the TextField no longer has focus - the Button does.

Alternatively, you should verify that props.deferUpdates is not set to be true. If this property is active, props.text will not update until AFTER the user applies the current text, and so your condition will actually not happen unless the props.text field ALREADY has more than 3 characters when the user begins typing.