Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vaadin TextField action at every key pressed

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

like image 729
Paolo Forgia Avatar asked Jan 29 '26 19:01

Paolo Forgia


1 Answers

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);
like image 125
user3551612 Avatar answered Jan 31 '26 09:01

user3551612



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!