2

In Vaadin 7 there are no KeyListener in TextField only on EnterKey press.

I'm looking for an add-on which contains a SuperImmediateTextField but compatible with Vaadin 7.

I use Vaadin version 7.1.8

Paolo Forgia
  • 6,572
  • 8
  • 46
  • 58

1 Answers1

5

You can use TextChangeListener. For example:

// Text field with maximum length
final TextField tf = new TextField("My Eventful Field");
tf.setValue("Initial content");
tf.setMaxLength(20);

// Counter for input length
final Label counter = new Label();
counter.setValue(tf.getValue().length() +
                 " of " + tf.getMaxLength());

// Display the current length interactively in the counter
tf.addTextChangeListener(new TextChangeListener() {
    public void textChange(TextChangeEvent event) {
        int len = event.getText().length();
        counter.setValue(len + " of " + tf.getMaxLength());
    }
});

// The lazy mode is actually the default
tf.setTextChangeEventMode(TextChangeEventMode.LAZY);
user3551612
  • 206
  • 3
  • 10