Directory

← Back

SearchDropDown

SearchDropDown provides search field with drop down for suggestions

Author

Contributors

Rating

SearchDropDown is designed to be used when your application needs to perform query or queries to resolve suggestions for search field. And when set of possible suggestions is too large to be stored in memory in hope that those might be needed.

Sample code

public static final String VALUES[] = { "alfa", "bravo", "charlie", "delta", "echo", "foxtrot", "golf", "hotel",
    "india", "juliett", "kilo", "lima", "mike", "november", "oscar", "papa", "quebec", "romea", "sierra",
    "tango", "uniform", "victor", "whiskey", "xray", "yankee", "zulu" };

SimpleSearchDropDown simpleSearch = new SimpleSearchDropDown(query -> {
    // For empty query, do not provide any suggestions
    final String cleaned = query.toLowerCase().trim();
    if(cleaned.isEmpty()) {
        return Collections.EMPTY_LIST;
    }

    // Normally here you would perform database or REST query or queries, to find suitable suggestions.
    // Simple API is always synchronous, so when you want to go to asynchronous use base class.
    return Arrays.stream(VALUES).filter(v -> v.contains(cleaned)).collect(Collectors.toList());
});
simpleSearch.setPlaceHolder("Search Phonetic Alphabets");
simpleSearch.addSearchListener(e -> Notification.show("User selected: " + e.getText()));

Links

Compatibility

(Loading compatibility data...)

Was this helpful? Need more help?
Leave a comment or a question below. You can also join the chat on Discord or ask questions on StackOverflow.

Version

Adds clear (search value) and click (at field icon) events.

Released
2017-04-26
Maturity
EXPERIMENTAL
License
Apache License 2.0

Compatibility

Framework
Vaadin 8.0+
Vaadin 8.2+ in 0.2.0
Browser
Opera
Safari
Google Chrome
Internet Explorer
Microsoft Edge
Online