maxschuster / Vaadin-AutocompleteTextField

A Vaadin TextField with autocomplete (aka word completion) functionality
https://vaadin.maxschuster.eu/AutocompleteTextField/
Apache License 2.0
9 stars 6 forks source link

"Missing Suggestion Key {0}" Error #28

Open idil-k opened 5 years ago

idil-k commented 5 years ago

Hello,

I get "missing suggestion key {0}" error, here is how to reproduce it on the interface:

  1. enter a text which has a not empty suggestion list (assume "test") image

  2. enter a text with an empty suggestion list

image

  1. check that the suggestion extension is empty

  2. push the keydown

  3. check that you see previous suggestions (suggestions belonging to test) image

  4. click on a suggestion

  5. check the "missing suggestion key {0}" exception on the log.

image

In other words, although the suggestions array is updated in the java code, it is possible to observe the previous suggestions on the UI. If you select from the previous suggestions, it cannot find the key on the current suggestions list and gives this error. Here is the text field implementation:

 public AutocompleteTextField createEditor() {

        field = new AutocompleteTextField(getLabel());

        if (getValue() != null) {
            field.setValue(getValue());
        }

        field.setDelay(150); // Delay before sending a query to the server
        field.setItemAsHtml(false); // Suggestions contain html formating. If true, make sure that the html is save to use!
        field.setMinChars(0); // The required value length to trigger a query
        field.setScrollBehavior(ScrollBehavior.NONE); // The method that should be used to compensate scrolling of the page
        field.setSuggestionLimit(50); // The max amount of suggestions send to the client. If the limit is >= 0 no limit is applied
        field.setRequiredIndicatorVisible(isMandatory());

        // update the suggestions with respect to the text entered at text field
        field.setSuggestionProvider(query -> fetchSuggestions(query.getTerm()));

        field.addSelectListener((AutocompleteEvents.SelectListener) event -> onSuggestionSelection(event.getSuggestion()));
        field.addValueChangeListener(event -> setValue(event.getValue()));

        return field;
    }

I would really appreciate it if you could help. Also thanks for the useful plug in :)