I am using Angular JS with Bootstrap UI typeahead, and pulling data from a REST service. The items in the array include town lists (towns served) that Ive combined, filtered out duplicates and created a 'townlist' array that the typeahead field uses. Everything works great.
The issue I need help with is when searching the town/city names, some use same words as each other (ie. Bedford, New Bedford, Brookfield, West Brookfield, East Brookfield) When a user types 'Bedford' the results for 'New Bedford' also appear.
I would like to match the EXACT array value, and only display results if it matches. So if a user searches Bedford, it will not include "New Bedford" in the results (unless an item contains both strings)
Im wondering if there is a simple way to solve this, or if I will need to include a custom filter.
In troubleshooting this, I generated a second array of all the two name towns that cause issues... I don't mind a solution where I simply run a custom filter with conditions to check if the query string matches any.
<input id="townsrch" type="text" class="form-control input-sm" ng-model="selected" uib-typeahead="town for town in towns | filter:$viewValue | limitTo:8" placeholder="search by town" typeahead-editable="false" ng-change="updateView()" typeahead-on-select="onSelect($item, $model, $label)">
<div ng-show="textsearch || selected" class="item team-item asp_an_fadeInDown ng-cloak" ng-repeat="x in names | filter:textsearch | filter:selected | orderBy:'title.rendered'">
<slick id="theresultingslides" slides-to-show="4" slides-to-scroll="1" data="names" ng-if="viewLoaded" settings="slickConfig">
<a class="asp_res_image_url" href="{{ x.link }}">
<div class="asp_image" style="background-image: url('{{x._embedded['wp:featuredmedia'][0].media_details.sizes.full.source_url}}');">
<div class="void"></div>
</div>
</a>
<div class="asp_content">
<h3><a class="asp_res_url" href="{{ x.link }}">{{x.title.rendered}}<span class="overlap"></span></a></h3>
<div class="etc"></div>
<p class="desc"></p><p class="emp-info"><strong>{{stripBr(x.acf.team_member_title)}}</strong><br/>
{{x.acf.team_member_branch_location}}<br />
<small>{{stripWww(x.acf.team_member_email)}}</small></p>
<div class="town-list-info"><p><small>{{x.acf.team_member_town}}</small></p></div>
</div>
<div class="clear"></div>
</div>
</slick>
<script>
angular.module('teamApp', ['slickCarousel','ui.bootstrap'])
.controller('namesCtrl', function($http, $scope, $timeout) {
$http.get("/wp-json/wp/v2/team-member?_embed&per_page=100")
.then(function (response) {
..... unrelated stuff here ......