From: Michael J. Rubinsky Date: Sun, 21 Feb 2010 00:19:01 +0000 (-0500) Subject: allow for passing the choices through a filtering function X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=6e0146ec58430833a1f37b62d473980268e90a45;p=horde.git 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. --- 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