Below is the input box for which I want an autocomplete feature:
<input auto-complete-user ng-hide="searchFilter.AssignedToAnyOne" ng-model="searchFilter.FilterByUser"
placeholder="Name / Company name" type="text" id="txtFilterUser"
class="filterUser form-control input-sm" />
And the angularJS directive -
BTWebApp.directive('autoCompleteUser', function ($timeout) {
if (localStorage[1] != undefined) {
return function (scope, iElement, iAttrs) {
iElement.autocomplete({
source: JSON.parse(localStorage[1]),
select: function () {
$timeout(function () {
iElement.trigger('input');
}, 0);
}
});
};
}});
The autocomplete works fine, except that once I have selected an option from the list, the autocomplete triggers again, thereby prompting me the selected item again which is very annoying. When I remove the iElement.trigger('input');
however, it works fine but the model doesn't get updated.
I referred this jsFiddle before using it in my code, the problem only occurs when I use it in my project code, it works perfectly fine in that jsFiddle. I don't know what I'm missing here. Is this something to do with bootstrap or when localstorage is used? coz that's the only difference I find between my code and the jsFiddle. Please help.