Typeahead icon indicating copy to clipboard operation
Typeahead copied to clipboard

[Question]

Open CopperBeardy opened this issue 2 years ago • 2 comments

ran into a edge case when adding new items.

if you had a list with "Foo bar" and ""Foo boo" in it and you wanted to add "Foo" the typeahead provide no way to do this, as it has found suggestions, even though none match exactly.

you can change the search to look for exact match instead of look for terms that contain the search value such as private async Task<IEnumerable<string>> SearchItems(string searchText) => Task.FromResult(Items.Where(x => x.Name.ToLower().Equals(searchText.ToLower())).ToList()); even though this would show the notfoundtemplate, you would not get any suggestions unless they were exactly the same as the search text which would negate the purpose of the suggestions

I can easily write code to add the item to the collection, however I can access the methods to close the results template and select the item added as the methods built in are all private.

Is there a workaround so that if the exact match is not found it will show display a hybrid view of the notfoundtemplate and the resulttemplate so you can either choose to add it as a new item or select one of the existing options

CopperBeardy avatar Mar 05 '22 13:03 CopperBeardy

Unfortunately there doesn't seem to be any way to do this, at least when I check the code here: https://github.com/Blazored/Typeahead/blob/main/src/Blazored.Typeahead/BlazoredTypeahead.razor.cs#L486

Kampfmoehre avatar Jul 22 '22 15:07 Kampfmoehre

Because of this, I have resigned to only use the control as a dropdown with add-new-functionality.

I have done this by always return empty result when typing (triggering Add-new..,), otherwise return all categories (for dropdown):

private async Task<IEnumerable<string>> SearchCategories(string searchText)
{
      var result = string.IsNullOrEmpty(searchText)
      ? categories
      : new List<string>();

      return await Task.FromResult(result);
}

EDIT: exact hit should return the item, not show the "Add-new"

thejaff2 avatar Aug 12 '22 08:08 thejaff2