Commits

Anonymous committed e8e493a

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

  • Participants
  • Parent commits e5bb1e7
  • Tags v0.1

Comments (0)

Files changed (2)

autocomplete/media/js/autocomplete.js

         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;

autocomplete/widgets.py

 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).
 AC_TEMPLATE = u'''
 <div>
   <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>
 </div>
 '''
     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())