-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Notification on Selection for Typeahead #433
Comments
@EvilClosetMonkey I'm looking into this one right now. I perfectly understand your use-case now but I think that we shouldn't be directly translating jQuery concepts to the AngularJS world. With AngularJS we are relaying to 2-way data binding a lot, especially in input fields. Here I'm getting an impression that you want to mix searching for records and editing records. Let's say I do a form for searching / editing part numbers. If I've got only one form with multiple filelds where typeaheads are bound to the IMHO the better solution here would be have a separate search field where users can type either a part number or its name. Typeahead would allow you to retrieve the whole record and use it to data-bind other fields. Having said all the above I'm not trying to force you to change your UI or your flow. As I've said implementing selection callback would be trivial but I want to make sure that new code is added only when needed. We want to keep this library concise and focused and as such I want to make sure that I understand use-cases before adding new code. Would be great if we could collaborate on this one to get to the best solution. |
@pkozlowski-opensource, I agree that |
I'm needing this exact functionality as well, an event that fires when the user selects something from the typeahead. @EvilClosetMonkey I agree with your notion of having an event return with a hook to determine which typeahead (or model). I'm already encountering this use-case of multiple typeaheads on a single page... |
@ecolman-ap @EvilClosetMonkey sorry, I kind of forgotten about this one... You will have to bear with me, as I'm still puzzled about the exact use-case. As I was saying already events on selection would be trivial to implement... but I'm failing to see why we would need them with data-binding! Could we make this discussion less abstract by focusing on a real use-case? Could one of you guys setup a plunker that exposes a problem / use-case you are trying to tackle? Once again, I want this typeahead to be the best autocomplete widget on earth but I don't want to add code for nothing... |
..Also, doesn't |
I'm using typeahead for a search and I'd like to know the difference between a user initiated search (they click a button), a typeahead item selection and just typing into the input. These events would need to be handled differently:
There is no way to differentiate between typing in the input and a selection from the typeahead. I suppose you could map a GUID to each item and try to parse the GUID each time in the ng-change function... Here is a plnkr use-case: |
No, For example -- if the callback is querying a database, you would not want to fire off a new Alternatively, the user may type in "Encom Corporation" which is not a typeahead option. This is still may be a valid entry (i.e., the user does not have to enter an existing value), but a I will work on a Plunkr when I have a chance. Not hard to make one up, just need the free time to do it. |
I'm using the typeahead for tagging. When the user selects an item from the typeahead I would like to push the tag object onto an array of selected tags and clear the input. Here's my plnkr use case: http://plnkr.co/edit/j0org6wwen7Qzew57NrK?p=preview |
The example provided by @johnobe is my exact use case. |
@johnobe @jamarparris @EvilClosetMonkey OK, I'm convinced :-) Will push a fix somewhere next week. Feel free to open a PR if you want it faster - should be really easy one. |
Awesome. Right now I pass to typeahead an array of objects (and then access the name using dot notation) so it'd be great if it returned the full object that was selected so that I can access other attributes such as id, etc. |
@jamarparris yes, in fact the only thing we need to decide upon is the exact syntax and params passed to this selection callback. I can see 2 main options: <input ... typeahead-on-select='selectCallback'> where the
OR (I think I like this one better): <input ... typeahead-on-select='selectCallback'($modelValue, $viewValue)> Of course the list of arguments could be extended (adding label, for example). What do you guys think? |
I do like the second option as like you say, you could add additional arguments which could be handy. |
I like the extensible nature of the 2nd option, but I've never seen an AngularJS callback work in the way illustrated in the 2nd option. Admittedly I'm still pretty new the framework and the power behind it. Is that method something supported elsewhere in the framework? |
@EvilClosetMonkey AngularJS core is full of examples that work like option (2). For example you can pass an optional |
@pkozlowski-opensource Excellent News! I agree with the others that option (2) provides a bit more flexibility. |
@pkozlowski-opensource I like option 2 for the flexibility, but it isn't pretty. Can we keep the arguments optional and be able to use option 1 unless otherwise needed? |
Would a notification when "no matches" are found be something to consider while we're at it? I am creating a quick entry form, and need a way to detect when the user is entering an item not part of the data set. At that point it would prompt them somehow to create a new entry with that value. Any suggestions? |
@brancusi You would need an additional action to know the user is done typing. On that action you could use existing mechanisms to do a check and add the new entry if necessary. |
Just landed a fix for this via 91ac17c. Check this unit test for the usage scenario:
|
I know this is a very old issue, but the following code isn't working:
$viewValue is undefined, why? |
typeahead-on-select does work @hectormateosoblanca. This worked for me. @JobaDiniz $viewValue does not exist in the spec. See:
|
Implement event notification for user selection of typeahead, so developer can capture selection and perform additional additional actions.
The AngularStrap project's typeahead, a wrapper for Bootstrap (vs. native AngularJS), fires a common event for all typeahead fields.
Example:
$http
request as field is filled.$http
request for complete employee record and fills in remaining form elements.Additionally, typeahead is hooked up to name field so user can type in name instead of Employee ID. Same process as above follows.
As a result, it would be very beneficial if each typeahead had its own
updater
callback instead of a single common event fired when any typeahead is updated. Multiple typeaheads could exist on the same page.Below is a jQuery implementation of the concept:
HTML:
JavaScript:
Typeahead selection event could return the selected value or the selection object. If selected object can be returned it opens up ability to query database only once, pulling a complete record with a single typeahead selection.
Basic extension of use case:
The notion is simply that an value from a typeahead field could one piece of a larger record, which could by queried on if the developer has access to the updater (to use Twitter Bootstrap terminology) event.
The text was updated successfully, but these errors were encountered: