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

Custom search function #40

Open
jordigasau opened this issue Jul 28, 2023 · 1 comment
Open

Custom search function #40

jordigasau opened this issue Jul 28, 2023 · 1 comment

Comments

@jordigasau
Copy link

Hello, I'm trying to modify the search behaviour to be hyphen insensitive so when the user types "Alava", he will get a result "Álava" as a match. I wonder if we could have a similar function like "item-projection" to define the search behaviour.

Many thanks

@jordigasau
Copy link
Author

jordigasau commented Jul 28, 2023

Right now I have found a workaround by overiding the filteredItems computed method as follows but it would be very interesting to be able to overide it as a parameter. By the way, I wonder if this sort of solution (overriding a function/method) is good practice. Many thanks!

SimpleTypeahead.computed.filteredItems = (self) => {
  // Normalize string before performing the search
  const regexp = new RegExp(
    self.escapeRegExp(
      self.input.normalize('NFD').replace(/[\u0300-\u036f]/g, '')
    ),
    'i'
  );

  return self.items.filter((item) =>
    self
      .itemProjection(item.normalize('NFD').replace(/[\u0300-\u036f]/g, ''))
      .match(regexp)
  );
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant