Germano Gabbianelli committed e8e493a

AutocompleteWidget supports now initial value;
autocomplete.js adds automatically the "yui-skin-sam" class to document.body.

Comments (0)

Files changed (2)


         datasource.resultTypeList = false;
         var input = document.getElementById("id_"+name);
         var container = document.createElement("div");
         YAHOO.util.Dom.insertAfter(container, input);
+        if (!YAHOO.util.Dom.hasClass(document.body, "yui-skin-sam"))
+            YAHOO.util.Dom.addClass(document.body, "yui-skin-sam");
         var autocomplete = new YAHOO.widget.AutoComplete(input, container, datasource);
         autocomplete.resultTypeList = false;


 from django.forms import widgets
 from django.utils.safestring import mark_safe
 from django.core.urlresolvers import reverse
+from django.utils.encoding import force_unicode
+from django.forms.util import flatatt
 # FIXME not ready for admin edit page, need ac_id_%(name)s prefill (2 line of js).
   <input type="hidden" name="%(name)s" id="id_hidden_%(name)s" />
-  <input type="text" id="id_%(name)s" />
+  <input type="text" id="id_%(name)s" %(attrs)s />
   <script type="text/javascript">autocomplete("%(name)s", "%(url)s", %(force_selection)s);</script>
     def render(self, name, value, attrs=None, choices=()):
         #input = super(AutoComplete, self).render(name, value, attrs)
         url = reverse(self.view_name, args=[self.ac_name])
-        force_selection = str(self.force_selection).lower()
+        force_selection = ['false', 'true'][self.force_selection]
+        if value:
+            attrs['value'] = force_unicode(value)
+        del value
+        attrs = flatatt(self.build_attrs(attrs))
         return mark_safe(self.AC_TEMPLATE % locals())