Hide the dropdown when no items are found

4 posts, 1 answers
  1. Ferdinando
    Ferdinando avatar
    9 posts
    Member since:
    Mar 2016

    Posted 22 Mar Link to this post

    Hi,

    Is it possible to hide the suggestions view when no items are found?

  2. Answer
    Sophi
    Admin
    Sophi avatar
    99 posts

    Posted 22 Mar Link to this post

    Hi Ferdinando,

    Yes, you can hide the suggestion list when there are no matching items.

    In order to do this you should conform to the TKAutoCompleteDelegate protocol and implement the autocomplete:willShowSuggestionList: method. This method provides you with the array of matches according to the input. You should check if there are any matches and in case there are no matches you should hide the suggestions list. Consider the following code snippet.
    -(void)autoComplete:(TKAutoCompleteTextView *)autocomplete willShowSuggestionList:(NSArray<__kindof TKAutoCompleteToken *> *)suggestionList
    {
        if (suggestionList.count == 0) {
            autocomplete.suggestionView.hidden = YES;
        }
    }


    Regards,
    Sophi
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. DevCraft banner
  4. Miguel
    Miguel avatar
    4 posts
    Member since:
    Apr 2016

    Posted 15 Apr in reply to Sophi Link to this post

    With 2015.3.1105 framework version I get always a suggestionList.count = 0 in this delegate function, even when there are matching items.

    ¿Any work around?

  5. Miguel
    Miguel avatar
    4 posts
    Member since:
    Apr 2016

    Posted 15 Apr in reply to Miguel Link to this post

    I found it myself.

    -(void)autoComplete:(TKAutoCompleteTextView *)autocomplete willShowSuggestionList:(NSArray<__kindof TKAutoCompleteToken *> *)suggestionList
    {
        NSInteger items = ((TKSuggestionListView*)autocomplete.suggestionView).items.count;
        if (items == 0) {
            autocomplete.suggestionView.hidden = YES;
        } else {
            autocomplete.suggestionView.hidden = NO;
        }
    }

Back to Top
DevCraft banner