Commits

Anonymous committed 48aa608

The autocomplete js function is now an object and can be customized (YUI).
See http://developer.yahoo.com/yui/autocomplete/ to learn how to customize it.
I've tested my changes only with Firefox and Chromium hoping they work with IE
too.

  • Participants
  • Parent commits cf21296

Comments (0)

Files changed (2)

File autocomplete/media/js/yui_autocomplete.js

+function yui_autocomplete(name, ac_url, force_selection) {
 
-function yui_autocomplete(name, ac_url, force_selection) {
-    YAHOO.util.Event.onDOMReady(function () {
+    this.name = name;
+    this.ac_url = ac_url;
+    this.force_selection = force_selection;
+
+    this.setup = function () {
         var datasource = new YAHOO.util.XHRDataSource(ac_url);
         datasource.responseType = YAHOO.util.XHRDataSource.TYPE_JSON;
         datasource.responseSchema = {
             for (var i in original)
                 parsed.result.push({"id": original[i][0], "label": original[i][1]});
             return parsed;
-        }
+        };
         datasource.resultTypeList = false;
 
         var input = document.getElementById("id_"+name);
         autocomplete.forceSelection = force_selection;
 
         var selected_item = {label: null, id: null};
-        var hidden = document.getElementById("id_hidden_"+name)
+        var hidden = document.getElementById("id_hidden_"+name);
         autocomplete.itemSelectEvent.subscribe(function (type, args) {
             selected_item = args[2];
             hidden.value = selected_item.id;
             if (selected_item.label != input.value && !force_selection)
                 hidden.value = input.value;
         });
-    });
-}
+        this.datasource = datasource;
+        this.autocomplete = autocomplete;
+    };
+    YAHOO.util.Event.onDOMReady(this.setup, null, this);
+};
 
 autocomplete = yui_autocomplete;

File autocomplete/widgets.py

 <div>
   <input type="hidden" name="%(name)s" id="id_hidden_%(name)s" value="%(hidden_value)s" />
   <input type="text" id="id_%(name)s" value="%(value)s" %(attrs)s />
-  <script type="text/javascript">autocomplete("%(name)s", "%(url)s", %(force_selection)s);</script>
+  <script type="text/javascript">var ac_%(name)s = new autocomplete("%(name)s", "%(url)s", %(force_selection)s);</script>
 </div>
 '''