Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] #264

Open
CopperBeardy opened this issue Mar 5, 2022 · 2 comments
Open

[Question] #264

CopperBeardy opened this issue Mar 5, 2022 · 2 comments
Labels
Question Question about this project Triage Issue needs to be triaged

Comments

@CopperBeardy
Copy link

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 CopperBeardy added Question Question about this project Triage Issue needs to be triaged labels Mar 5, 2022
@Kampfmoehre
Copy link

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

@thejaff2
Copy link

thejaff2 commented Aug 12, 2022

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"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question Question about this project Triage Issue needs to be triaged
Projects
None yet
Development

No branches or pull requests

3 participants