Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Typeahead does not support "group by" or "track by" syntax #506

Closed
bowsersenior opened this issue Jun 5, 2013 · 8 comments
Closed

Typeahead does not support "group by" or "track by" syntax #506

bowsersenior opened this issue Jun 5, 2013 · 8 comments

Comments

@bowsersenior
Copy link

It seems that the regex used to parse the typeahead expression has gotten out of sync with the syntax available in the select directive. I can see that keeping these in sync could be an ongoing challenge as there doesn't seem to be an easy way to extract the regex and parser from select. Perhaps the correct long-term fix is for AngularJS to extract the parser for select into a reusable service and have typeahead use that directly.

In the short-term, perhaps the typeahead regex and parser can be updated to at least add support for the "group by" syntax, which can be useful, I think. In general, I think it is a great idea to re-use the exact same syntax as select.

Here are the details. The select directive's ng-options attribute allows a "group by" clause:

select as label group by group for value in array

OR 

select as label group by group for (key, value) in object

(from: http://docs.angularjs.org/api/ng.directive:select)

However, it seems that typeahead does not parse for the "group by" syntax:

Also, recently a "track by" syntax was added:

The relevant lines in the current AngularJS source where the regex is defined:

... and where the syntax is parsed using the regex above:

@pkozlowski-opensource
Copy link
Member

@bowsersenior while the syntax used in typeahead is heavily inspired by the one used in the <select> one we are not striving to be 100% the same as not all the concepts from select make sense for autocomplete.

When I was writing the initial version of the typeahead I've left over group by on purpose as I didn't have a use case for this. Do you have one? Or are you just after consistency in general?

For the track by it is a little bit more complex as autocomplete can fetch matches over $http so we are potentially working with very large data sets. I don't think we can map all the concepts from to typeahead directly - we simply don't have (nor should have) entire set of matches in memory to compare against. Could you share the exact, functional use case you are struggling with?

@bowsersenior
Copy link
Author

Thanks for the clarification. I think it is worth implementing the exact same syntax as select but I understand it might be a challenge to do so. At the least, an update to the documentation for typeahead is required.

The use case for "group by" is when you want to organize results. Imagine you have an input field where you can type in a username and you want the typeahead list to group the users by their role ("Admin", "Customer Service", etc.).

I think consistency is a more important concern, though. Introducing a syntax that is close to that for select but with some subtle distinctions can be complex to understand and manage. It is much simpler to specify absolutely the same syntax, though it does not mean that it would be easy to make that happen.

In the meanwhile, I think a necessary first step is to clarify the documentation for typeahead to clarify the syntax. Right now,the documentation for typeahead states:

"it uses the same, flexible syntax as the select directive"

And the only info on the typeahead syntax is a link to the select directive's documentation page.

@pkozlowski-opensource
Copy link
Member

@bowsersenior thnx for getting back to me on this one. Yes, totally agree, docs need to be clarified.

What I was asking more directly is if you got an immediate use-case that needs attention. I understand that grouping would be nice to add and I can imagine use-cases for this. At the same time there are other parts where I think time be better invested, custom templates for matched items being one example. But I will let people vote here :-)

@bowsersenior
Copy link
Author

@pkozlowski-opensource I understand your point of view. Actually, I personally don't have a use case right now for this.

@scamden
Copy link
Contributor

scamden commented Jul 4, 2013

i have a use case for this. my search is a multi-search. it could be over contacts, companies, etc. i want to group the results by type (and would like headers on those sections). i'm actually considering angular typeahead for our rewrite of our search widget but it would be hard to justify if i can't do this.

@pkozlowski-opensource
Copy link
Member

@scamden Great that you have a use case for this one! Personally I don't need this functionality at the moment so a pull request (with tests) would be the fastest way of getting this functionality in the project!

@pkozlowski-opensource
Copy link
Member

@bowsersenior @scamden we are preparing for a bigger overhaul of this project and as indicated already this is not a top priority for me. Feel free to open a PR with test if you need this one and have an idea of implementation. Thnx!

@scamden
Copy link
Contributor

scamden commented Jul 27, 2013

ok thanks! i'll get on that as soon as we rewrite the uses of the search widget that need the group by. actually if you could point me at some good resources to get better at testing @pkozlowski-opensource that would really help. we're just beginning to convert our old gwt app to angular and we want to make testing a priority. we have a few tests, but looking briefly at the tests for this project it's clear to me that we could improve. thoughts?

codedogfish pushed a commit to codedogfish/angular-ui-bootstrap that referenced this issue Sep 15, 2015
Trim the trailing space left by a new tag's label.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants