codenameone / CodenameOne

Cross-platform framework for building truly native mobile apps with Java or Kotlin. Write Once Run Anywhere support for iOS, Android, Desktop & Web.
https://www.codenameone.com/
Other
1.7k stars 403 forks source link

TextField DataChangeListener receives extra event after losing focus #1835

Open diamondobama opened 8 years ago

diamondobama commented 8 years ago

When you add a DataChangeListener to a TextField and you type some text, the TextField receives extra event when it lost focus.

How to reproduce Issue:

Add a TextField to a form and apply a data change listener, then output the text as you type, click outside the TextField and check your log. You will see the last value repeated.

Test Code:

Form form = new Form(); TextField txtTest = new TextField(""); txtTest.addDataChangeListener((evtt, evt2) -> { System.out.println(txtTest.getText()); } form.add(txtTest); form.show();

Test with "1234".

Expected Output: 1 12 123 1234

Output: 1 12 123 1234 1234

codenameone commented 8 years ago

I'm not sure we'd want to fix that. DataChangedListener is verbose by definition and it's the responsibility of the listener to only use the event callbacks that matter. Some code might rely on this over verboseness and break.