From 6e0146ec58430833a1f37b62d473980268e90a45 Mon Sep 17 00:00:00 2001 From: "Michael J. Rubinsky" Date: Sat, 20 Feb 2010 19:19:01 -0500 Subject: [PATCH] allow for passing the choices through a filtering function Filter the autocomplete choices for the prettyautocompleter to remove items that are already present in the list. --- horde/js/autocomplete.js | 2 ++ horde/js/prettyautocomplete.js | 11 ++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/horde/js/autocomplete.js b/horde/js/autocomplete.js index 7cb070227..aaea2d45f 100644 --- a/horde/js/autocomplete.js +++ b/horde/js/autocomplete.js @@ -38,6 +38,7 @@ Autocompleter.Base = Class.create({ onSelect: Prototype.K, onShow: Prototype.K, onType: Prototype.K, + filterCallback: Prototype.K, paramName: elt.readAttribute('name'), tokens: [], keydownObserver: this.elt @@ -95,6 +96,7 @@ Autocompleter.Base = Class.create({ $(this.opts.indicator).hide(); } + choices = this.opts.filterCallback(choices); if (!choices.size()) { if (this.knl) { this.knl.hide(); diff --git a/horde/js/prettyautocomplete.js b/horde/js/prettyautocomplete.js index fe69ce7f1..453d80bb5 100644 --- a/horde/js/prettyautocomplete.js +++ b/horde/js/prettyautocomplete.js @@ -15,7 +15,8 @@ var PrettyAutocompleter = Class.create({ minTriggerWidth: 100, // Allow for a function that filters the display value // This function should *always* return escaped HTML - displayFilter: function(t) { return t.escapeHTML() } + displayFilter: function(t) { return t.escapeHTML() }, + filterCallback: this._filterChoices.bind(this) }, params); // Array to hold the currently selected items to ease with removing @@ -203,5 +204,13 @@ var PrettyAutocompleter = Class.create({ realValues.push(this.selectedItems[x].rawValue); } $(this.p.items).value = realValues.join(','); + }, + + _filterChoices: function(c) + { + this.selectedItems.each(function(item) { + c = c.without(item.displayValue); + }); + return c; } }); \ No newline at end of file -- 2.11.0