The surface autofills somewhat - select the input value as you type

The mutliple component is tied to some data in the background, and if none of the results provided automatically matches the search criteria, the entered value of the input field should be added to the list when you press enter.

However, if some results meet the search criteria, we would still like the component to somehow allow the user to add the entered value to the list and not select the value from the list, if necessary.

The functionality we are trying to achieve is actually very similar to adding email recipients. The To field of the Autocomplete is (somewhat) tied to the user's contacts. But, despite this, the user can add new email addresses when creating a new letter.

How can we make the autocomplete component accept the actual value entered, which will be added when you press enter, or adding ";" at the end of input?

Setting "forceelection = false" doesn't seem to work. We use direct 3.5.

thanks uros

+4
source share
1 answer

consider the following complete autocomplete method

public List<String> completeEmailIds(String keyword) { List<String> emailsIds = new ArrayList<String>(); List<String> availableEmailIds = aMethodThatReturnsAvailableEmailIdsBasedOnKeyword(String keyword); if(!(availableEmailIds.isEmpty())){ emailIds.addAll(availableEmailIds); }else{ emailIds.add(keyword); // if availableEmailIds returns empty, then new typed email will also be added. } return emailIds; } 

In this way, autocomplete elements are created and returned. You can use them in the autocomplete component for multiple values. Hope this helps

+1
source

Source: https://habr.com/ru/post/1485033/


All Articles