I have a problem with UI bootstrap Typeahead. Here is plnkr, and explaination is below.
http://plnkr.co/edit/lvy1Xu13xfFBjHbIY68H?p=preview
I would like to be able to select one state from the states listed by Typeahead, but also to be able to create new state in the same form, with properties name and flag by writing state name that doesn't exist.
Everything works as expected when you select a state from Typeahead. You select whole object, properties "state" and "flag" gets selected too. The problem occurs when you write a string that doesn't match any of those options listed in Typeahead. Let's say you want to make state "myState" Then the ng-model is string and not object like it is when you select one option from typeahead and it is not possible to enter flag property because you can't create property on string.
Is there any way that I can change uib-typeahead settings or change ng-model somehow, make some function that changes ng-model from string to object, or something like that?
<input type="text" ng-model="customPopupSelected" placeholder="state" uib-typeahead="state as state.name for state in statesWithFlags | filter:{name:$viewValue}" typeahead-popup-template-url="customPopupTemplate.html" class="form-control">
<input type="text" ng-model="customPopupSelected.flag" placeholder="flag" class="form-control">
Here is simplified explaination of what I am trying to acheive. When I select state from Typeahead, state looks like this:
state = {
"name": "Arizona",
"flag": "9/9d/Flag_of_Arizona.svg/45px-Flag_of_Arizona.svg.png"
}
When i start typing and type a state that doesn't exist state is a string.
state = "myState"
so I am not able to add new "state.name", and then add "state.flag" property to state object. So I would like to get around this somehow and be able to make my own states if it is even possible.
state = {
"name": "myState",
"flag": "mystate-flag.svg.png"
}