[Django] #28871: Autocomplete select for new lines in inline model do not open

32 views
Skip to first unread message

Django

unread,
Dec 1, 2017, 3:29:23 AM12/1/17
to django-...@googlegroups.com
#28871: Autocomplete select for new lines in inline model do not open
-------------------------------------+-------------------------------------
Reporter: Marcus | Owner: nobody
Götling |
Type: Bug | Status: new
Component: | Version: 2.0
contrib.admin | Keywords: autocomplete
Severity: Normal | select2
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 1 |
-------------------------------------+-------------------------------------
When a model has an Inline model, autocomplete select does not show for
new rows.

Select box is is replaced with Select2 style, but clicking it does not
show the select list.

**model.py**
{{{#!python
class Item(models.Model):
name = models.CharField(max_length=100)

class Category(models.Model):
name = models.CharField(max_length=100)

def __str__(self):
return self.name

class LineItem(models.Model):
item = models.ForeignKey(
'Item',
on_delete=models.CASCADE
)
category = models.ForeignKey(
'Category',
on_delete=models.CASCADE
)
}}}

**admin.py**
{{{#!python
class LineItemInline(admin.TabularInline):
model = LineItem
extra = 1

autocomplete_fields = ('category',)

@admin.register(Item)
class ItemAdmin(admin.ModelAdmin):
list_display = ('name',)
search_fields = ('name',)

inlines = [
LineItemInline
]

@admin.register(Category)
class CategoryAdmin(admin.ModelAdmin):
list_display = ('name',)
search_fields = ('name',)
}}}


== Github repo
With demo and instructions on how to reproduce

https://github.com/gotling/bug-django2-autocomplete

--
Ticket URL: <https://code.djangoproject.com/ticket/28871>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Dec 1, 2017, 3:29:58 AM12/1/17
to django-...@googlegroups.com
#28871: Autocomplete select for new lines in inline model do not open
-------------------------------------+-------------------------------------
Reporter: Marcus Götling | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 2.0
Severity: Normal | Resolution:
Keywords: autocomplete | Triage Stage:
select2 | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 1
-------------------------------------+-------------------------------------
Changes (by Marcus Götling):

* Attachment "screenshot" added.

Inline

Django

unread,
Dec 1, 2017, 5:25:16 AM12/1/17
to django-...@googlegroups.com
#28871: Autocomplete select for new lines in inline model do not open
--------------------------------------+------------------------------------

Reporter: Marcus Götling | Owner: nobody
Type: Bug | Status: new

Component: contrib.admin | Version: 2.0
Severity: Normal | Resolution:
Keywords: autocomplete select2 | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 1
--------------------------------------+------------------------------------
Changes (by Claude Paroz):

* stage: Unreviewed => Accepted


Comment:

I was able to reproduce, but only for new forms added by clicking on the
"Add another ..." link.

--
Ticket URL: <https://code.djangoproject.com/ticket/28871#comment:1>

Django

unread,
Dec 1, 2017, 8:04:49 AM12/1/17
to django-...@googlegroups.com
#28871: Autocomplete select for new lines in inline model do not open
--------------------------------------+------------------------------------
Reporter: Marcus Götling | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 2.0
Severity: Release blocker | Resolution:

Keywords: autocomplete select2 | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 1
--------------------------------------+------------------------------------
Changes (by Tim Graham):

* cc: Johannes Hoppe (added)
* severity: Normal => Release blocker


--
Ticket URL: <https://code.djangoproject.com/ticket/28871#comment:2>

Django

unread,
Dec 1, 2017, 8:52:43 AM12/1/17
to django-...@googlegroups.com
#28871: Autocomplete select for new lines in inline model do not open
-------------------------------------+-------------------------------------
Reporter: Marcus Götling | Owner: Johannes
| Hoppe
Type: Bug | Status: assigned

Component: contrib.admin | Version: 2.0
Severity: Release blocker | Resolution:
Keywords: autocomplete | Triage Stage: Accepted
select2 |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 1
-------------------------------------+-------------------------------------
Changes (by Johannes Hoppe):

* owner: nobody => Johannes Hoppe
* status: new => assigned


Comment:

Might I just say: This is an amazing bug report! I'll look into it this
weekend, thanks :)

--
Ticket URL: <https://code.djangoproject.com/ticket/28871#comment:3>

Django

unread,
Dec 1, 2017, 9:06:05 AM12/1/17
to django-...@googlegroups.com
#28871: Autocomplete select for new lines in inline model do not open
-------------------------------------+-------------------------------------
Reporter: Marcus Götling | Owner: Johannes
| Hoppe
Type: Bug | Status: assigned
Component: contrib.admin | Version: 2.0
Severity: Release blocker | Resolution:
Keywords: autocomplete | Triage Stage: Accepted
select2 |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 1
-------------------------------------+-------------------------------------

Comment (by Tim Graham):

The Django 2.0 release is scheduled for today so maybe me or somebody else
would look at the issue if you don't have time today.

--
Ticket URL: <https://code.djangoproject.com/ticket/28871#comment:4>

Django

unread,
Dec 1, 2017, 1:27:59 PM12/1/17
to django-...@googlegroups.com
#28871: Autocomplete select for new lines in inline model do not open
-------------------------------------+-------------------------------------
Reporter: Marcus Götling | Owner: Johannes
| Hoppe
Type: Bug | Status: assigned
Component: contrib.admin | Version: 2.0
Severity: Release blocker | Resolution:
Keywords: autocomplete | Triage Stage: Accepted
select2 |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 1
-------------------------------------+-------------------------------------

Comment (by Tim Graham):

I found that this patch will allow the "Add another" autocomplete widgets
to work, except for the first one that's added.
{{{ #!diff
diff --git a/django/contrib/admin/static/admin/js/autocomplete.js
b/django/contr
index 15321f9..2fa1920 100644
--- a/django/contrib/admin/static/admin/js/autocomplete.js
+++ b/django/contrib/admin/static/admin/js/autocomplete.js
@@ -29,10 +29,7 @@

$(document).on('formset:added', (function() {
return function(event, $newFormset) {
- var $widget = $newFormset.find('.admin-autocomplete');
- // Exclude already initialized Select2 inputs.
- $widget = $widget.not('.select2-hidden-accessible');
- return init($widget);
+ return $newFormset.find('.admin-
autocomplete').djangoAdminSelect2()
};
})(this));
}(django.jQuery));
}}}
It looks like the contents of `$newFormset` for the first "add another" is
different from the contents of subsequent "add anothers".

--
Ticket URL: <https://code.djangoproject.com/ticket/28871#comment:5>

Django

unread,
Dec 1, 2017, 2:04:18 PM12/1/17
to django-...@googlegroups.com
#28871: Autocomplete select for new lines in inline model do not open
-------------------------------------+-------------------------------------
Reporter: Marcus Götling | Owner: Tim
| Graham

Type: Bug | Status: assigned
Component: contrib.admin | Version: 2.0
Severity: Release blocker | Resolution:
Keywords: autocomplete | Triage Stage: Accepted
select2 |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 1
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* owner: Johannes Hoppe => Tim Graham


Comment:

I think a have a working patch and am writing a test.

--
Ticket URL: <https://code.djangoproject.com/ticket/28871#comment:6>

Django

unread,
Dec 1, 2017, 8:56:11 PM12/1/17
to django-...@googlegroups.com
#28871: Autocomplete select for new lines in inline model do not open
-------------------------------------+-------------------------------------
Reporter: Marcus Götling | Owner: Tim
| Graham
Type: Bug | Status: assigned
Component: contrib.admin | Version: 2.0
Severity: Release blocker | Resolution:
Keywords: autocomplete | Triage Stage: Accepted
select2 |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 1
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/9406 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/28871#comment:7>

Django

unread,
Dec 1, 2017, 10:42:08 PM12/1/17
to django-...@googlegroups.com
#28871: Autocomplete select for new lines in inline model do not open
-------------------------------------+-------------------------------------
Reporter: Marcus Götling | Owner: Tim
| Graham
Type: Bug | Status: closed
Component: contrib.admin | Version: 2.0
Severity: Release blocker | Resolution: fixed

Keywords: autocomplete | Triage Stage: Accepted
select2 |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 1
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"81057645f61fe545f4f11737dbd3040043ed2436" 81057645]:
{{{
#!CommitTicketReference repository=""
revision="81057645f61fe545f4f11737dbd3040043ed2436"
Fixed #28871 -- Fixed initialization of autocomplete widgets in "Add
another" inlines.

Also allowed autocomplete widgets to work on AdminSites with a name other
than 'admin'.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28871#comment:8>

Django

unread,
Dec 1, 2017, 10:42:11 PM12/1/17
to django-...@googlegroups.com
#28871: Autocomplete select for new lines in inline model do not open
-------------------------------------+-------------------------------------
Reporter: Marcus Götling | Owner: Tim
| Graham
Type: Bug | Status: closed
Component: contrib.admin | Version: 2.0
Severity: Release blocker | Resolution: fixed
Keywords: autocomplete | Triage Stage: Accepted
select2 |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 1
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"63d425c679423f14a60b5b1bc1b2a59dc28ec42b" 63d425c6]:
{{{
#!CommitTicketReference repository=""
revision="63d425c679423f14a60b5b1bc1b2a59dc28ec42b"
[2.0.x] Fixed #28871 -- Fixed initialization of autocomplete widgets in
"Add another" inlines.

Also allowed autocomplete widgets to work on AdminSites with a name other
than 'admin'.

Backport of 81057645f61fe545f4f11737dbd3040043ed2436 from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28871#comment:9>

Django

unread,
Dec 2, 2017, 9:59:18 AM12/2/17
to django-...@googlegroups.com
#28871: Autocomplete select for new lines in inline model do not open
-------------------------------------+-------------------------------------
Reporter: Marcus Götling | Owner: Tim
| Graham
Type: Bug | Status: closed
Component: contrib.admin | Version: 2.0
Severity: Release blocker | Resolution: fixed
Keywords: autocomplete | Triage Stage: Accepted
select2 |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 1
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"7664fe275910bb31fcca2d54844bedde19fc4ed9" 7664fe2]:
{{{
#!CommitTicketReference repository=""
revision="7664fe275910bb31fcca2d54844bedde19fc4ed9"
Refs #28871 -- Fixed admin_views selenium test failure.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28871#comment:10>

Django

unread,
Dec 2, 2017, 10:03:02 AM12/2/17
to django-...@googlegroups.com
#28871: Autocomplete select for new lines in inline model do not open
-------------------------------------+-------------------------------------
Reporter: Marcus Götling | Owner: Tim
| Graham
Type: Bug | Status: closed
Component: contrib.admin | Version: 2.0
Severity: Release blocker | Resolution: fixed
Keywords: autocomplete | Triage Stage: Accepted
select2 |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 1
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"dbdf5deab07d879146e106724d9ad80e9064c4f5" dbdf5dea]:
{{{
#!CommitTicketReference repository=""
revision="dbdf5deab07d879146e106724d9ad80e9064c4f5"
[2.0.x] Refs #28871 -- Fixed admin_views selenium test failure.

Backport of 7664fe275910bb31fcca2d54844bedde19fc4ed9 from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28871#comment:11>

Reply all
Reply to author
Forward
0 new messages