#75 Enter handling in text control

open
nobody
5
2014-08-14
2012-03-22
Tim B
No

The current text control ignores pressing of enter, it would be better if it moved onto the next control instead (or had that as an option). I've created my own varient with this functionality for now but that is extending the obsolete TextFieldControl class so I'm not sure if I'm supposed to be doing it that way.

public class TextFieldControl extends de.lessvoid.nifty.controls.textfield.TextFieldControl {

private boolean nextFieldOnEnter;

@Override
public void bind(Nifty niftyParam, Screen screenParam, Element newElement, Properties properties, Attributes controlDefinitionAttributes) {
    super.bind(niftyParam, screenParam, newElement, properties, controlDefinitionAttributes);

    if (properties.containsKey("nextFieldOnEnter")) {
      setNextFieldOnEnter(Boolean.valueOf(properties.getProperty("nextFieldOnEnter")));
    }
}

public boolean isNextFieldOnEnter() {
    return nextFieldOnEnter;
}

public void setNextFieldOnEnter(boolean nextFieldOnEnter) {
    this.nextFieldOnEnter = nextFieldOnEnter;
}

@Override
public boolean inputEvent(final NiftyInputEvent inputEvent) {
    if (nextFieldOnEnter && inputEvent == NiftyInputEvent.SubmitText) {
        return super.inputEvent(NiftyInputEvent.NextInputElement);
    } else {
        return super.inputEvent(inputEvent);
    }
}

}

Discussion