diff --git a/src/ion-autocomplete.js b/src/ion-autocomplete.js index fd1fb79..1a11faf 100644 --- a/src/ion-autocomplete.js +++ b/src/ion-autocomplete.js @@ -49,7 +49,8 @@ angular.module('ion-autocomplete', []).directive('ionAutocomplete', [ this.loadingIcon = valueOrDefault($attrs.loadingIcon, undefined); this.manageExternally = valueOrDefault($attrs.manageExternally, "false"); this.clearOnSelect = valueOrDefault($attrs.clearOnSelect, "true"); - this.ngModelOptions = valueOrDefault($scope.$eval($attrs.ngModelOptions), {}); + this.clearOnRemove = valueOrDefault($attrs.clearOnRemove, "false"); + this.ngModelOptions = valueOrDefault($scope.$eval($attrs.ngModelOptions), {}); this.openClass = valueOrDefault($attrs.openClass, 'ion-autocomplete-open'); this.closeClass = valueOrDefault($attrs.closeClass, 'ion-autocomplete-close'); @@ -161,7 +162,7 @@ angular.module('ion-autocomplete', []).directive('ionAutocomplete', [ // store the selected items if (!isKeyValueInObjectArray(ionAutocompleteController.selectedItems, - ionAutocompleteController.itemValueKey, ionAutocompleteController.getItemValue(item, ionAutocompleteController.itemValueKey))) { + ionAutocompleteController.itemValueKey, ionAutocompleteController.getItemValue(item, ionAutocompleteController.itemValueKey))) { // if it is a single select set the item directly if (ionAutocompleteController.maxSelectedItems == "1") { @@ -200,6 +201,12 @@ angular.module('ion-autocomplete', []).directive('ionAutocomplete', [ // clear the selected items if just one item is selected if (!angular.isArray(ionAutocompleteController.selectedItems)) { ionAutocompleteController.selectedItems = []; + if (ionAutocompleteController.clearOnRemove == "true") { + ionAutocompleteController.searchQuery = undefined; + ionAutocompleteController.cancelClick(); + } + + } else { // remove the item from the selected items and create a copy of the array to update the model. // See https://github.com/angular-ui/ui-select/issues/191#issuecomment-55471732 @@ -251,7 +258,7 @@ angular.module('ion-autocomplete', []).directive('ionAutocomplete', [ // show the loading icon ionAutocompleteController.showLoadingIcon = true; - var queryObject = {query: query, isInitializing: isInitializing}; + var queryObject = { query: query, isInitializing: isInitializing }; // if the component id is set, then add it to the query object if (ionAutocompleteController.componentId) { @@ -350,7 +357,7 @@ angular.module('ion-autocomplete', []).directive('ionAutocomplete', [ var onTouchStart = function (e) { scrolling.moved = false; // Use originalEvent when available, fix compatibility with jQuery - if (typeof(e.originalEvent) !== 'undefined') { + if (typeof (e.originalEvent) !== 'undefined') { e = e.originalEvent; } scrolling.startX = e.touches[0].clientX; @@ -360,7 +367,7 @@ angular.module('ion-autocomplete', []).directive('ionAutocomplete', [ // check if the finger moves more than 10px and set the moved flag to true var onTouchMove = function (e) { // Use originalEvent when available, fix compatibility with jQuery - if (typeof(e.originalEvent) !== 'undefined') { + if (typeof (e.originalEvent) !== 'undefined') { e = e.originalEvent; } if (Math.abs(e.touches[0].clientX - scrolling.startX) > 10 || @@ -402,7 +409,7 @@ angular.module('ion-autocomplete', []).directive('ionAutocomplete', [ // function to call the model to item method and select the item var resolveAndSelectModelItem = function (modelValue) { // convert the given function to a $q promise to support promises too - var promise = $q.when(ionAutocompleteController.modelToItemMethod({modelValue: modelValue})); + var promise = $q.when(ionAutocompleteController.modelToItemMethod({ modelValue: modelValue })); promise.then(function (promiseData) { // select the item which are returned by the model to item method @@ -483,7 +490,7 @@ angular.module('ion-autocomplete', []).directive('ionAutocomplete', [ // set the model value of the model ngModelController.$parsers.push(function (viewValue) { return ionAutocompleteController.getItemValue(viewValue, ionAutocompleteController.itemValueKey); - }); + }); });