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.71k stars 405 forks source link

AutoCompleteTextField prints wrong value in the simulator #2318

Closed codenameone closed 6 years ago

codenameone commented 6 years ago

This seems to be a regression related to text input:

Form hi = new Form("Hi World", BoxLayout.y());
String[] l =  new String[]{"aaa", "bbb", "ccc", "ddd", "eee"};
AutoCompleteTextField ac = new AutoCompleteTextField(l);
ac.addActionListener((e) -> {
    System.out.println("T: " + ac.getText());
});

hi.add(ac);
hi.show();

The field will be aaa but the printout is T:.

The action event is invoked once by the synchronous editing code which completes when the popup is clicked and has no text yet. When the selection is made the action event isn't fired for some reason.

shannah commented 6 years ago

I'd be surprised if that ever worked. The actionEvent is likely firing when the text field loses focus by clicking on the drop-down list. After selecting the item in the drop down list will trigger an event to the list listener (AutoCompleteTextField.addListListener()), but not to the action listeners of the text field.

shannah commented 6 years ago

It would be easy to make it fire two action events in this case - the first one with the field value prior to selecting an option in the autocomplete list - and the second one with the value after selecting the option in autocomplete. Making it fire just one action event (after selecting the option) would be trickier ... high probability of causing regressions if not done very carefully.

codenameone commented 6 years ago

I can live with that. The class needs a rewrite at some point anyway so a smaller fix would be better.