Getting Text from TextField when user presses return key

Hello folks,



This is probably a very simple question. I have a Nifty TextField I want to read out after the user pressed Return. Unfortunately, while Buttons listen for the return key as “interactOnClick”, TextFields do not. TextfieldChangedEvents don’t even get fired on pressing return. How do I properly listen for “User has pressed Return”?

This should work:



[java] @NiftyEventSubscriber(id = "myTextField")

public void onMyTextFieldInputEvent(final String id,

final NiftyInputEvent event) {

if (NiftyInputEvent.SubmitText.equals(event)) {

// Do Something

}

}[/java]

2 Likes

Works like a charm, thank you.