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

Typeahead with pre-populated model #203

Closed
brendanreen opened this issue Mar 8, 2013 · 12 comments
Closed

Typeahead with pre-populated model #203

brendanreen opened this issue Mar 8, 2013 · 12 comments

Comments

@brendanreen
Copy link

Opening a separate issue as per @pkozlowski-opensource here.

If the typeahead model is bound to an object prior to user input (e.g., with a server response), the typeahead shows the entire model object instead of the display value.

@brendanreen
Copy link
Author

Example: http://plnkr.co/edit/2jmcZY?p=preview

@brendanreen
Copy link
Author

Since mapping only occurs when an option is selected, nothing is parsing pre-loaded input. I changed modelCtrl.$render to parse modelCtrl.$viewValue rather than selected, and the directive works as expected for both simple (array of strings) and complex (array of objects) models.

Example: http://plnkr.co/edit/y25fqb?p=preview

@petebacondarwin
Copy link
Member

+1

@pkozlowski-opensource
Copy link
Member

Definitively on my radar, in fact this is the next issue that I want to tackle. But this is a bit more complex since we can't assume that we have all the data to re-create input's text. Current binding language is very flexible so it might be that someone retrieved a complex object from a server, used it to render a label but is binding an id only.

I think that the proper solution here is to let people provide input formatter (that would take model and could otput whatever formatted value);

@drozzy
Copy link

drozzy commented Mar 23, 2013

Typeahead shows incorrect value when it loads an existing model.

Does the as syntax work? For some reason, when I load a page with pre-populated data, it shows me an id instead of the name. Here is my example:

   <input ng-model="entity.Asset.Id" typeahead="a.Asset.Id as a.Asset.Name for a in assets"  />

where my assets is an array of Asset objects.

Asset = {'Id' : 123, 'Name' : 'Blah'}

@drozzy
Copy link

drozzy commented Mar 23, 2013

Here is the relevant line I think from source, "ui-bootstrap-tpls-0.2.0.js", line No. 1611:

element.val(parserResult.viewMapper(scope, locals) || modelCtrl.$viewValue);

@petebacondarwin
Copy link
Member

@drozzy this is precisely what @brendanreen suggests above. More or less!! :-)

@drozzy
Copy link

drozzy commented Mar 24, 2013

@petebacondarwin Yes, that fixed it! Would be great to know when it's rolled into the main - so I can update ;-)

@pkozlowski-opensource
Copy link
Member

Will be working on the fix + tests later today

@pkozlowski-opensource
Copy link
Member

@drozzy @petebacondarwin @brendanreen Could you guys give the latest version from master a try?

@drozzy
Copy link

drozzy commented Mar 25, 2013

Any chance you could compile me a version with a template inside it :-) Mine are not under templates etc...

@pkozlowski-opensource
Copy link
Member

@drozzy you can grab a built SNAPSHOT version from the CI server:
http://ci.angularjs.org/job/angularui-bootstrap/ws/dist/ui-bootstrap-tpls-0.3.0-SNAPSHOT.js

Don't wait too long though as it will get replaced on the next build (!).

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

4 participants