Skip to content

Commit

Permalink
Solves #19: Keyboard selection selects the actual value of the array,…
Browse files Browse the repository at this point in the history
… instead of just selecting the item at the index of array
  • Loading branch information
kamal0808 committed Sep 6, 2017
1 parent 9a0b28e commit f69ec21
Show file tree
Hide file tree
Showing 7 changed files with 231 additions and 196 deletions.
13 changes: 12 additions & 1 deletion demo/client/lib/js/materializecss-autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ angular.module('material.autocomplete.templates', []).run(['$templateCache', fun
(function () {
'use strict';

var MaterialAutocompleteCntrl = function ($scope, $element, $q, $timeout) {
var MaterialAutocompleteCntrl = function ($scope, $element, $q, $timeout, $filter) {
var self = this;

$timeout(function () {
Expand Down Expand Up @@ -207,6 +207,10 @@ angular.module('material.autocomplete.templates', []).run(['$templateCache', fun
self.itemList = convertArrayToObject(self.itemList);
}

if (self.itemList && typeof self.itemList[0] === 'object') {
self.itemListCopy = angular.copy(self.itemList);
}

if (self.remoteMethod) {
self.itemList = [];
}
Expand Down Expand Up @@ -460,11 +464,17 @@ angular.module('material.autocomplete.templates', []).run(['$templateCache', fun
if (self.selectedItem[self.displayProperty1] !== searchText) {
self.selectedItem = null;
self.hidden = shouldHide();
if (self.itemList && self.itemListCopy) {
self.itemList = angular.copy(self.itemListCopy);
}
}
}
else if (self.remoteMethod) {
fetchResults(searchText);
}
else if (self.itemList) {
self.itemList = $filter('filter')(self.itemListCopy, searchText);
}
}

/**
Expand Down Expand Up @@ -682,6 +692,7 @@ angular.module('material.autocomplete.templates', []).run(['$templateCache', fun
'$element',
'$q',
'$timeout',
'$filter',
MaterialAutocompleteCntrl
]);

Expand Down
193 changes: 97 additions & 96 deletions demo/client/lib/js/materializecss-autocomplete.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f69ec21

Please sign in to comment.