What I want:
Listen for KeyDownEvent on a TextField. If the key is Return, clear the TextField contents. Accept more input.
Right now, when hitting return, the element simply deselects and no more text is registered. I tried downloading the Castle Crashers UI demo to see if they have a text input anywhere but its just a black screen.
Calling .Focus() on myTextField doesn’t do anything. Any workarounds for selecting a TextField after hitting Return on it?
focusController.focusedElement says its the same element focus, before and after hitting Return
I figured it out. To focus on a TextField after you’ve hit Return on it, you have to wait a frame, call .Blur(), then .Focus()
Hi @BackgroundMover !
Here’s what the custom logic to override a default behaviour on the TextField would look like. The PreventDefault is important here as it prevents the default TextField logic from being executed. In the case of return, it triggers a focus change which might be why you have to manually add focus back to the element.
myField.RegisterCallback<KeyDownEvents>((evt) => {
if (evt.keyCode == KeyCode.Enter || evt.character == '/n')
{
evt.StopPropagation();
evt.PreventDefault();
}
}, TrickleDown.TrickleDown);