4
votes

The autocomplete component (mutliple) is bound to some data in background and in case none of auto provided results fits the search criteria, the typed value of the input field shall be added to the list when pressing enter.

However, in case some results do fit the search criteria, we would still like the component to somehow allow the user to add the typed value to the list and not select a value from the list, if so desired.

The functionality we are trying to achieve is actually very similar as adding email recipients to email. "To" field Autocomplete (multiple) is bound to user contacts. But despite that fact, the user can still add new email addresses when creating new email.

How can we make the autocomplete component to accept the actual typed value to be added when pressing enter, or adding ";" at the end of the input?

Set "forceselection=false" does not seem to work. We are using primefaces 3.5.

thanks, uros

1
Can you please provide some code? It will help us help youPrasad Kharkar
please put the code xhtml and managed beanmeyquel

1 Answers

1
votes

consider the following completeMethod for autocomplete

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;
}

This way, the autocomplete items will be created and returned. You can use them in autocomplete component for multiple values. Hope this helps