bootstrap icon indicating copy to clipboard operation
bootstrap copied to clipboard

Typeahead > When using an object field in the "as", it's not possible to set value programmatically

Open julienmeyer opened this issue 13 years ago • 3 comments

I configure a typehead like this : "obj.id as obj.name for obj in objList" with "ng-model=selectedValue".

If I set selectedValue equals to an obj.id, the typehead didn't find the wanted obj. But if I set selectedValue equals to obj, it works.

If the user, select a item from the typehead, the selectedValue is the id and not the complete object. So I don't understand why I can't not set programmatically a value.

Example : http://plnkr.co/edit/iRR7cbIxrpjLpVywZ96u

Thanks,

Julien

julienmeyer avatar Jul 31 '13 13:07 julienmeyer

I think it's not a bug, because you try to set your model to something which does not exists in your $scope.state

jendib avatar Aug 02 '13 21:08 jendib

@ julienmeyer

In your plunk you're using version 0.4.0. This was fixed in version 0.5.0, however, this may not be the behavior you want.

In version 0.5.0 displays the id in the input. c4e169cb

Just change the version number in your plunk to see the difference between both versions.

exocom avatar Aug 16 '13 02:08 exocom

@jendib it works as designed. For the longer discussion on why it behaves the way it does see https://github.com/angular-ui/bootstrap/issues/274 but in short it boils down to the fact that you can fetch matches dynamically from the server and at the initial rendering time we might not have enough info to render a label.

Fortunately starting from 0.5.0 you've control over this behavior with the new typeahead-input-formatter attribute that allows you to specify a function that will be called to get a label to rendered inside the input. You can see it action in this plunk: http://plnkr.co/edit/aeYIkgJyMpdMx5x7fesF?p=preview

If you guys have any idea on how to make this easier on people I'm all ears!

pkozlowski-opensource avatar Aug 20 '13 11:08 pkozlowski-opensource