allow for passing the choices through a filtering function
authorMichael J. Rubinsky <mrubinsk@horde.org>
Sun, 21 Feb 2010 00:19:01 +0000 (19:19 -0500)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Sun, 21 Feb 2010 00:19:01 +0000 (19:19 -0500)
Filter the autocomplete choices for the prettyautocompleter to remove
items that are already present in the list.

horde/js/autocomplete.js
horde/js/prettyautocomplete.js

index 7cb0702..aaea2d4 100644 (file)
@@ -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();
index fe69ce7..453d80b 100644 (file)
@@ -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