Commits

Ian Struble committed 1657a88

Fixed placement of lookup/search icon when multiple selections are allowed.

Comments (0)

Files changed (3)

django/contrib/admin/media/css/widgets.css

 .ui-menu .ui-menu-item a {
     border: 1px solid #fcfdfd;
 }
-ul.ui-menu li {
+ul.ui-menu li,
+.ui-autocomplete-value {
     list-style-type: none;
 }
 .ui-state-hover, .ui-state-focus {
 .ui-autocomplete-value a {
     margin-left: 0.5em;
 }
+.djangoautocomplete-wrapper > * { 
+    float: left; 
+}
+.djangoautocomplete-wrapper > ul { 
+    clear: left; 
+}
+.related-lookup {
+    position: relative;
+    top: 4px;
+    left: 2px;
+}

django/contrib/admin/widgets.py

         else:
             search_icon = u''
         return mark_safe(u''.join((
+            u'<div class="djangoautocomplete-wrapper">\n',
             u'<input%s />\n' % flatatt(hidden_attrs),
             u'<input%s />\n' % flatatt(normal_attrs),
+            initial_objects,
+            u'</div>\n',
             search_icon,
-            initial_objects,
             u'<script type="text/javascript">',
             u'django.jQuery("#id_%s").djangoautocomplete(%s);' % (name, options),
             u'</script>\n',

tests/regressiontests/admin_widgets/tests.py

         w = AutocompleteWidget(widget_settings)
         field_name = 'test'
         expected = "\n".join((
+            '<div class="djangoautocomplete-wrapper">',
             '<input type="hidden" name="test" value="%(band_pk)s" id="id_hidden_%(field_name)s" />',
             '<input type="text" value="%(band_name)s" />',
+            '</div>',
             '<script type="text/javascript">django.jQuery("#id_%(field_name)s").djangoautocomplete({"force_selection": true, "multiple": %(multiple)s, "source": "../autocomplete/%(field_name)s/"});</script>',
             ''
             )) % {'field_name': field_name,
     def _get_expected(self, name, bands, show_search=False):
         bands = [] if bands is None else bands
         expected = [
+            '<div class="djangoautocomplete-wrapper">',
             '<input type="hidden" name="%(field_name)s" value="%(band_pks)s" id="id_hidden_%(field_name)s" />',
             '<input type="text" value="" />',  # input is for data entry only
             ]
+        if bands:                
+            expected += ['<ul class="ui-autocomplete-values">']
+            expected += ['<li>%s</li>' % b.name for b in bands]
+            expected += ['</ul>']
+        expected += ['</div>']
         if show_search:
-            expected.append('<a href="../../../admin_widgets/band/?t=id" class="related-lookup" id="lookup_id_%s" onclick="return showRelatedObjectLookupPopup(this);"> <img src="%simg/admin/selector-search.gif" width="16" height="16" alt="Lookup" /></a>' % (name, settings.ADMIN_MEDIA_PREFIX))
-        if bands:                
-                expected += ['<ul class="ui-autocomplete-values">']
-                expected += ['<li>%s</li>' % b.name for b in bands]
-                expected += ['</ul>']
+            expected += ['<a href="../../../admin_widgets/band/?t=id" class="related-lookup" id="lookup_id_%s" onclick="return showRelatedObjectLookupPopup(this);"> <img src="%simg/admin/selector-search.gif" width="16" height="16" alt="Lookup" /></a>' % (name, settings.ADMIN_MEDIA_PREFIX)]
         expected += [
             '<script type="text/javascript">django.jQuery("#id_%(field_name)s").djangoautocomplete({"force_selection": true, "multiple": %(multiple)s, "source": "../autocomplete/%(field_name)s/"});</script>',
             ''
 
         w = MultipleAutocompleteWidget(with_search_settings)
         bands_none = None
-        expected_none = self._get_expected('test_none', bands_none, True)
+        expected_none = self._get_expected('test_none', bands_none, show_search=True)
         self.assertEqual(
             conditional_escape(w.render('test_none', bands_none, attrs={})),
             expected_none,