Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions inputDropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ angular.module('inputDropdown', []).directive('inputDropdown', [function() {
'<input type="text"' +
'name="{{inputName}}"' +
'placeholder="{{inputPlaceholder}}"' +
'ng-attr-placeholder="{{inputNgAttrPlaceholder}}"' +
'autocomplete="off"' +
'ng-model="inputValue"' +
'ng-required="inputRequired"' +
Expand All @@ -14,8 +15,8 @@ angular.module('inputDropdown', []).directive('inputDropdown', [function() {
'<ul ng-show="dropdownVisible">' +
'<li ng-repeat="item in dropdownItems"' +
'ng-click="selectItem(item)"' +
'ng-mouseenter="setActive($index)"' +
'ng-mousedown="dropdownPressed()"' +
'ng-tap="selectItem(item)"' +
'ng-mousedown="selectItem(item)"' +
'ng-class="{\'active\': activeItemIndex === $index}"' +
'>' +
'<span ng-if="item.readableName">{{item.readableName}}</span>' +
Expand All @@ -33,6 +34,7 @@ angular.module('inputDropdown', []).directive('inputDropdown', [function() {
inputRequired: '=',
inputName: '@',
inputPlaceholder: '@',
inputNgAttrPlaceholder: '@',
filterListMethod: '&',
itemSelectedMethod: '&'
},
Expand Down Expand Up @@ -75,7 +77,6 @@ angular.module('inputDropdown', []).directive('inputDropdown', [function() {
scope.$watch('selectedItem', function(newValue, oldValue) {
inputScope.updateInputValidity();

if (!angular.equals(newValue, oldValue)) {
if (newValue) {
// Update value in input field to match readableName of selected item
if (typeof newValue === 'string') {
Expand All @@ -85,11 +86,6 @@ angular.module('inputDropdown', []).directive('inputDropdown', [function() {
scope.inputValue = newValue.readableName;
}
}
else {
// Uncomment to clear input field when editing it after making a selection
// scope.inputValue = '';
}
}
});

scope.setInputActive = function() {
Expand All @@ -112,6 +108,9 @@ angular.module('inputDropdown', []).directive('inputDropdown', [function() {
}
else if (scope.allowCustomInput) {
inputScope.updateInputValidity();
if (scope.itemSelectedMethod) {
scope.itemSelectedMethod({item: scope.inputValue});
}
}

if (scope.filterListMethod) {
Expand Down