angular-ui / bootstrap

PLEASE READ THE PROJECT STATUS BELOW. Native AngularJS (Angular) directives for Bootstrap. Smaller footprint (20kB gzipped), no 3rd party JS dependencies (jQuery, bootstrap JS) required. Please read the README.md file before submitting an issue!
http://angular-ui.github.io/bootstrap/
MIT License
14.3k stars 6.74k forks source link

Typeahead search looks for match in whole object #6652

Closed Fossil01 closed 6 years ago

Fossil01 commented 6 years ago

I have the following:

<input type="text" ng-model="selectedIssuedBy" uib-typeahead="company as company.name for company in companies | filter:$viewValue | limitTo:10" typeahead-editable="false" typeahead-select-on-exact="true" typeahead-show-hint="true" placeholder="Search company cards are issued by" class="form-control">

This is the company object (real data replaced with fake names):

{
  "id": "0233c7ee-dfc1-47c9-900c-632647014657",
  "name": "Airline Transporters United Ltd.",
  "coc_no": "123456",
  "meta": {
    "created": {
      "id": "0ee6cf39-5bf4-482d-80bf-1993978d1ee2",
      "assignee": "United Administrator",
      "timestamp": "2017-10-12T14:23:23.957913595Z"
    },
    "modified": {
      "id": "0ee6cf39-5bf4-482d-80bf-1993978d1ee2",
      "assignee": "United Administrator",
      "timestamp": "2017-10-12T14:23:23.957916995Z"
    }
  }
},
{
  "id": "0233c7ee-dfc1-47c9-900c-632647014657",
  "name": "Ground Transporters Ltd.",
  "coc_no": "123456",
  "meta": {
    "created": {
      "id": "0ee6cf39-5bf4-482d-80bf-1993978d1ee2",
      "assignee": "United Administrator",
      "timestamp": "2017-10-12T14:23:23.957913595Z"
    },
    "modified": {
      "id": "0ee6cf39-5bf4-482d-80bf-1993978d1ee2",
      "assignee": "United Administrator",
      "timestamp": "2017-10-12T14:23:23.957916995Z"
    }
  }
}

Now when I search for United it also matches the last object "Ground Transporters" because the word United also exists in the object under created.assignee. How do I fix this? I thought it should only match on company.name

Fossil01 commented 6 years ago

Okay never mind. While typing this it occurred to me I already had this issue once before and started looking through old code :-)

This fix was: filter:{name: $viewValue}