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.72k stars 409 forks source link

AutoCompleteTextField.setEditable(false) doesn't work as expected #2757

Closed jsfan3 closed 5 years ago

jsfan3 commented 5 years ago

I understand that AutoCompleteTextField.setEditable(false) can seems strange, because usually an AutoCompleteTextField should be editable. However I need to make it editable or not editable according to the user interactions.

More specifically, I expect that an AutoCompleteTextField is not editable if it shows the text without any chance to edit it and without showing the autocompleting list. Actually AutoCompleteTextField.setEditable(false) makes the autocompleting list appearing and it allows to select an item to change the text value of the AutoCompleteTextField.

Test case:

        Form hi = new Form("Auto Complete", new BoxLayout(BoxLayout.Y_AXIS));
        AutoCompleteTextField ac = new AutoCompleteTextField("Short", "Shock", "Sholder", "Shrek");
        ac.setMinimumElementsShownInPopup(5);
        ac.setText("S");
        ac.setEditable(false);
        hi.add(ac);
        hi.show();

Screenshot after tapping the letter S: autocomplete

I've already done several attempts to extend the AutoCompleteTextField to override the method setEditable to make it working, but without success.

codenameone commented 5 years ago

Wouldn't this be solved by something like:

public void showPopup() {
    if(isEditable()) {
         super.showPopup();
    }
}
jsfan3 commented 5 years ago

No, it doesn't solve. A code like the following has the same issue:

        Form hi = new Form("Auto Complete", new BoxLayout(BoxLayout.Y_AXIS));
        AutoCompleteTextField ac = new AutoCompleteTextField("Short", "Shock", "Sholder", "Shrek") {
            @Override
            public void showPopup() {
                if (isEditable()) {
                    super.showPopup();
                }
            }
        };
        ac.setMinimumElementsShownInPopup(5);
        ac.setText("S");
        ac.setEditable(false);
        hi.add(ac);
        hi.show();
codenameone commented 5 years ago

I committed a fix with a new method that should resolve it:

Form hi = new Form("Auto Complete", new BoxLayout(BoxLayout.Y_AXIS));
AutoCompleteTextField ac = new AutoCompleteTextField("Short", "Shock", "Sholder", "Shrek") {
    @Override
    protected boolean shouldShowPopup() {
        return isEditable();
    }
};
ac.setMinimumElementsShownInPopup(5);
ac.setText("S");
ac.setEditable(false);
hi.add(ac);
hi.show();        
jsfan3 commented 5 years ago

Thank you!

jsfan3 commented 5 years ago

I have a bad news...

Your fix works only in the Simulator.

Web-app -> Doesn't work on Safari and on Android Chrome Android native -> doesn't work Iphone native -> it seems working, but it's a fake: after some random tapping, it replaced the "S" with with "Shock" (like if the popup is present but not visible). After killing and reopening the app, I get the "S" replaced with "Short", tapping under the "S".

codenameone commented 5 years ago

I think the server deployment was partial. I just redeployed and it seems to have worked now. Probably fixes #2756 too

jsfan3 commented 5 years ago

No, it's not solved: after your redeployed all the platforms that I tested (Android native, iOS native, web-app) have the same issue: after some random tapping under the "S", it replaced the "S" with with "Shock", "Short", "Sholder" or another word of the list .

jsfan3 commented 5 years ago

The same issue is also in the Simulator, I've just noted it.

codenameone commented 5 years ago

This is deployed now, can you see if it resolved the issue?

jsfan3 commented 5 years ago

Thank you. Yes, I tried our test case and now it seems solved in all platforms except the Simulator. I clicked "Update Project Libs", but the bug is still present in the Simulator.

codenameone commented 5 years ago

I only updated the servers, updating the simulator will generate download noise for everyone so we'll wait for that next week.

jsfan3 commented 5 years ago

Ok