Re: [Django] #13068: The "Add another [inline object]" javascript doesn't respect prepopulated_fields settings

41 views
Skip to first unread message

Django

unread,
May 13, 2011, 11:32:20 AM5/13/11
to django-...@googlegroups.com
#13068: The "Add another [inline object]" javascript doesn't respect
prepopulated_fields settings
-------------------------------------+-------------------------------------
Reporter: hejsan | Owner: seanbrant
Type: | Status: reopened
Uncategorized | Component: contrib.admin
Milestone: 1.2 | Severity: Normal
Version: 1.3 | Keywords: prepopulated_field
Resolution: | inline add
Triage Stage: Accepted | Has patch: 1
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
-------------------------------------+-------------------------------------
Changes (by stan <stanislas.guerra__at__gmail.com>):

* status: closed => reopened
* severity: => Normal
* resolution: fixed =>
* version: SVN => 1.3
* easy: => 0
* keywords: => prepopulated_field inline add
* type: => Uncategorized


Comment:

I reopen the ticket because It still does not works with the
''StackedInline''.

The problem is in ''initPrepopulatedFields'' javascript function in the
''django/contrib/admin/edit_inline/{stacked,tabular}.html'' files and in
the way the selector are set in the html.

Having the following in my admin.py:


{{{
class CahierInline(admin.StackedInline):
model = models.Cahier
extra = 1
fieldsets = (
(None, {
'fields': (('ordre',), ('nom', 'euid', 'valide',),
'nom_court',)
}),
('périodicité', {
'fields': ('periodicite', 'jours_de_parution_semaine',
'jours_de_parution_mois',)
}),
)
prepopulated_fields = {'euid': ('nom',)}

}}}



For a TabularInline, the html produced looks like that :


{{{
<td class="euid prepopulated_field">
<input id="id_cahiers-1-euid" class="vTextField" type="text"
maxlength="50" name="cahiers-1-euid">
</td>
}}}

And with StackedInline :


{{{
<div class="form-row nom euid valide prepopulated_field">
<div class="field-box">
<label class="required" for="id_cahiers-1-nom">Nom:</label>
<input id="id_cahiers-1-nom" class="vTextField" type="text"
maxlength="100" name="cahiers-1-nom">
</div>
<div class="field-box">
<label class="required inline" for="id_cahiers-1-euid">Clé:</label>
<input id="id_cahiers-1-euid" class="vTextField" type="text"
maxlength="50" name="cahiers-1-euid">
</div>
<div class="field-box">
<input id="id_cahiers-1-valide" type="checkbox"
name="cahiers-1-valide" checked="checked">
<label class="vCheckboxLabel inline"
for="id_cahiers-1-valide">Valide</label>
</div>
</div>
}}}


The lookup in ''initPrepopulatedFields'' for the pre-populated input
cannot works in the last case (and is not possible unless with a crap)
because the class ''euid'' (''via field.field.name'') is too high in the
DOM.


There is at last two way to correct that :

1. put the ''field.field.name'' class on the div.field-box ;
2. change the lookup in ''initPrepopulatedFields'' for
''django/contrib/admin/edit_inline/{stacked,tabular}.html''.

I am a bit surprised that we have two different files
''admin/edit_inline/{stacked,tabular}.html'' with one using an include to
render the fieldset and the other doing it ''in-situ'' but having the
similar bits of javascript.
Those 2 files being factorizables (at least for the js part), adding some
differences in the behavior is not the best way so my patch implements the
first solution.
I didn't run the test suite so it may break some stuff because the render
is now like that :


{{{
<div class="form-row">
<div class="field-box nom">
<label class="required" for="id_cahiers-1-nom">Nom:</label>
<input id="id_cahiers-1-nom" class="vTextField" type="text"
maxlength="100" name="cahiers-1-nom">
</div>
<div class="field-box euid prepopulated_field">
<label class="required inline" for="id_cahiers-1-euid">Clé:</label>
<input id="id_cahiers-1-euid" class="vTextField" type="text"
maxlength="50" name="cahiers-1-euid">
</div>
<div class="field-box valide">...
</div>

}}}

--
Ticket URL: <http://code.djangoproject.com/ticket/13068#comment:18>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
May 13, 2011, 12:10:40 PM5/13/11
to django-...@googlegroups.com
#13068: The "Add another [inline object]" javascript doesn't respect
prepopulated_fields settings
-------------------------------------+-------------------------------------
Reporter: hejsan | Owner: seanbrant
Type: | Status: reopened
Uncategorized | Component: contrib.admin
Milestone: 1.2 | Severity: Normal
Version: 1.3 | Keywords: prepopulated_field
Resolution: | inline add
Triage Stage: Accepted | Has patch: 1
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
-------------------------------------+-------------------------------------

Comment (by seanbrant):

Im unable to confirm that this is not working for StackedInlines. Can you
confirm that it does not work when using the attached test
models.py/admin.py [1]? Also if you can attach a sample models.py/admin.py
that fail that would be helpful in debugging this.

Any other details like what exactly is not working would also be helpful.
Thanks!

[1] https://code.djangoproject.com/attachment/ticket/13068/models.py

--
Ticket URL: <http://code.djangoproject.com/ticket/13068#comment:19>

Django

unread,
May 13, 2011, 3:45:02 PM5/13/11
to django-...@googlegroups.com
#13068: The "Add another [inline object]" javascript doesn't respect
prepopulated_fields settings
-------------------------------------+-------------------------------------
Reporter: hejsan | Owner: seanbrant
Type: | Status: reopened
Uncategorized | Component: contrib.admin
Milestone: 1.2 | Severity: Normal
Version: 1.3 | Keywords: prepopulated_field
Resolution: | inline add
Triage Stage: Accepted | Has patch: 1
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
-------------------------------------+-------------------------------------

Comment (by anonymous):

It works in your example because you don't use fieldsets.

I have modified it to wrap the name and the slugs fields in the same group
and then it fails to populate.

http://code.djangoproject.com/attachment/ticket/13068/models.2.py

Cordialement,

Stanislas.

--
Ticket URL: <http://code.djangoproject.com/ticket/13068#comment:20>

Django

unread,
May 13, 2011, 3:53:38 PM5/13/11
to django-...@googlegroups.com
#13068: The "Add another [inline object]" javascript doesn't respect
prepopulated_fields settings
-------------------------------------+-------------------------------------
Reporter: hejsan | Owner: seanbrant
Type: | Status: reopened
Uncategorized | Component: contrib.admin
Milestone: 1.2 | Severity: Normal
Version: 1.3 | Keywords: prepopulated_field
Resolution: | inline add
Triage Stage: Accepted | Has patch: 1
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
-------------------------------------+-------------------------------------

Comment (by seanbrant):

I just tried using your attached admin with the fieldset addition and it
is still working for me.

--
Ticket URL: <http://code.djangoproject.com/ticket/13068#comment:21>

Django

unread,
May 13, 2011, 4:49:25 PM5/13/11
to django-...@googlegroups.com
#13068: The "Add another [inline object]" javascript doesn't respect
prepopulated_fields settings
-------------------------------------+-------------------------------------
Reporter: hejsan | Owner: seanbrant
Type: | Status: reopened
Uncategorized | Component: contrib.admin
Milestone: 1.2 | Severity: Normal
Version: 1.3 | Keywords: prepopulated_field
Resolution: | inline add
Triage Stage: Accepted | Has patch: 1
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
-------------------------------------+-------------------------------------

Comment (by stan <stanislas.guerra__at__gmail.com>):

We are talking about the StackedInlines added with the `Add Another`
button, are we ?

http://code.djangoproject.com/attachment/ticket/13068/screenshot-
stackedInline.png

I'am running Django-1.3, not the trunk and I have tested with the latest
Firefox and Safari.

--
Ticket URL: <http://code.djangoproject.com/ticket/13068#comment:22>

Django

unread,
May 13, 2011, 4:56:49 PM5/13/11
to django-...@googlegroups.com
#13068: The "Add another [inline object]" javascript doesn't respect
prepopulated_fields settings
-------------------------------------+-------------------------------------
Reporter: hejsan | Owner: seanbrant
Type: | Status: reopened
Uncategorized | Component: contrib.admin
Milestone: 1.2 | Severity: Normal
Version: 1.3 | Keywords: prepopulated_field
Resolution: | inline add
Triage Stage: Accepted | Has patch: 1
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
-------------------------------------+-------------------------------------

Comment (by seanbrant):

Im sorry I did not test the "Add another" you are correct I see the error
as well.

I just tried out your patch and it corrects the problem. Thanks!

--
Ticket URL: <http://code.djangoproject.com/ticket/13068#comment:23>

Django

unread,
Feb 18, 2012, 1:15:46 PM2/18/12
to django-...@googlegroups.com
#13068: The "Add another [inline object]" javascript doesn't respect
prepopulated_fields settings
-------------------------------------+-------------------------------------
Reporter: hejsan | Owner: seanbrant
Type: Bug | Status: reopened
Component: contrib.admin | Version: 1.3
Severity: Release blocker | Resolution:
Keywords: prepopulated_field | Triage Stage: Accepted
inline add | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 1
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by julien):

* severity: Normal => Release blocker


Comment:

[16953] actually introduced a regression as now the prepopulated fields
don't work for new inlines of any kind (stacked or tabular). The attached
patch fixes it. I'll now work on adding some Selenium tests.

--
Ticket URL: <https://code.djangoproject.com/ticket/13068#comment:27>

Django

unread,
Feb 18, 2012, 1:16:06 PM2/18/12
to django-...@googlegroups.com
#13068: The "Add another [inline object]" javascript doesn't respect
prepopulated_fields settings
-------------------------------------+-------------------------------------
Reporter: hejsan | Owner: seanbrant
Type: Bug | Status: reopened
Component: contrib.admin | Version: 1.3
Severity: Release blocker | Resolution:
Keywords: prepopulated_field | Triage Stage: Accepted
inline add | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 0
Needs tests: 1 | UI/UX: 1
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by julien):

* needs_tests: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/13068#comment:28>

Django

unread,
Feb 19, 2012, 11:42:13 AM2/19/12
to django-...@googlegroups.com
#13068: The "Add another [inline object]" javascript doesn't respect
prepopulated_fields settings
-------------------------------------+-------------------------------------
Reporter: hejsan | Owner: seanbrant
Type: Bug | Status: closed
Component: contrib.admin | Version: 1.3
Severity: Release blocker | Resolution: fixed
Keywords: prepopulated_field | Triage Stage: Accepted
inline add | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 0
Needs tests: 1 | UI/UX: 1
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by julien):

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


Comment:

In [17562]:
{{{
#!CommitTicketReference repository="" revision="17562"
Fixed #13068 (again) -- Corrected the admin stacked inline template to
allow prepopulated fields to work (Thanks Stanislas Guerra for the
report). Also fixed a regression introduced in [16953] where prepopulated
fields wouldn't be recognized any more due to the additional "field-" CSS
class name prefix.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/13068#comment:29>

Django

unread,
Oct 24, 2012, 4:41:40 PM10/24/12
to django-...@googlegroups.com
#13068: The "Add another [inline object]" javascript doesn't respect
prepopulated_fields settings
-------------------------------------+-------------------------------------
Reporter: hejsan | Owner: seanbrant
Type: Bug | Status: reopened

Component: contrib.admin | Version: 1.3
Severity: Release blocker | Resolution:
Keywords: prepopulated_field | Triage Stage: Accepted
inline add | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 0
Needs tests: 1 | UI/UX: 1
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by frankwiles):

* status: closed => reopened

* resolution: fixed =>


Comment:

I'm still seeing this in 1.4.2. It works for any Inlines that are created
because of 'extra', but adding additional ones the slug prepopulation
doesn't work.

--
Ticket URL: <https://code.djangoproject.com/ticket/13068#comment:30>

Django

unread,
Oct 25, 2012, 4:34:11 PM10/25/12
to django-...@googlegroups.com
#13068: The "Add another [inline object]" javascript doesn't respect
prepopulated_fields settings
-------------------------------------+-------------------------------------
Reporter: hejsan | Owner: seanbrant
Type: Bug | Status: reopened
Component: contrib.admin | Version: 1.3
Severity: Normal | Resolution:

Keywords: prepopulated_field | Triage Stage: Accepted
inline add | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 0
Needs tests: 1 | UI/UX: 1
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by aaugustin):

* severity: Release blocker => Normal


Comment:

Since the regression was fixed, this isn't a release blocker for 1.5.

--
Ticket URL: <https://code.djangoproject.com/ticket/13068#comment:31>

Django

unread,
Nov 25, 2012, 3:50:52 PM11/25/12
to django-...@googlegroups.com
#13068: The "Add another [inline object]" javascript doesn't respect
prepopulated_fields settings
-------------------------------------+-------------------------------------
Reporter: hejsan | Owner: seanbrant
Type: Bug | Status: reopened
Component: contrib.admin | Version: 1.3
Severity: Normal | Resolution:
Keywords: prepopulated_field | Triage Stage: Accepted
inline add | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 0
Needs tests: 1 | UI/UX: 1
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by julien):

Replying to [comment:30 frankwiles]:


> I'm still seeing this in 1.4.2. It works for any Inlines that are
created because of 'extra', but adding additional ones the slug
prepopulation doesn't work.

I'm afraid I can't reproduce the problem. Could you describe the issue in
more detail? In particular, what do you exactly mean by "adding additional
ones"? Is that via clicking the "+" green button?

--
Ticket URL: <https://code.djangoproject.com/ticket/13068#comment:32>

Django

unread,
Nov 21, 2013, 5:24:11 AM11/21/13
to django-...@googlegroups.com
#13068: The "Add another [inline object]" javascript doesn't respect
prepopulated_fields settings
-------------------------------------+-------------------------------------
Reporter: hejsan | Owner: seanbrant
Type: Bug | Status: new

Component: contrib.admin | Version: 1.3
Severity: Normal | Resolution:
Keywords: prepopulated_field | Triage Stage: Accepted
inline add | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 0
Needs tests: 1 | UI/UX: 1
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by bruno@…):

[17562] DoesntWork(tm) on Django 1.5.1 / (Mozilla Firefox 25.0.1, Chrome
31.0.1650.57) / Ubuntu 12.04

The problem comes from jQuery class selectors:

templates/admin/prepopulated_fields_js.html line 22:

{{{
$('.empty-form .form-row .field-{{ field.field.name }})
}}}

should be

{{{
$('.empty-form .form-row.field-{{ field.field.name }})
}}}

(no whitespace between ".form-row" and ".field-name")

Same thing in static/admin/js/inline.js line 246, replacing

{{{
dependencies.push('#' + row.find('.form-row .field-' +
field_name).find('input, select, textarea').attr('id'));
}}}

with

{{{
dependencies.push('#' + row.find('.form-row.field-' +
field_name).find('input, select, textarea').attr('id'));
}}}

fixes the problem.

--
Ticket URL: <https://code.djangoproject.com/ticket/13068#comment:34>

Django

unread,
Mar 11, 2015, 10:12:13 AM3/11/15
to django-...@googlegroups.com
#13068: The "Add another [inline object]" javascript doesn't respect
prepopulated_fields settings
-------------------------------------+-------------------------------------
Reporter: hejsan | Owner: seanbrant
Type: Bug | Status: new
Component: contrib.admin | Version: 1.7
Severity: Release blocker | Resolution:

Keywords: prepopulated_field | Triage Stage: Accepted
inline add |
Has patch: 0 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 1
-------------------------------------+-------------------------------------
Changes (by rafaelcapucho):

* cc: rafael.capucho@… (added)
* needs_better_patch: 0 => 1
* has_patch: 1 => 0
* version: 1.3 => 1.7


* severity: Normal => Release blocker


Comment:

The problem in prepopulated_fields when using inline are incredibly still
present in Django 1.7.5.

The solution proposed by bruno 16 months ago works well for Django 1.7.5.

--
Ticket URL: <https://code.djangoproject.com/ticket/13068#comment:35>

Django

unread,
Mar 11, 2015, 10:27:41 AM3/11/15
to django-...@googlegroups.com
#13068: The "Add another [inline object]" javascript doesn't respect
prepopulated_fields settings
-------------------------------------+-------------------------------------
Reporter: hejsan | Owner: seanbrant
Type: Bug | Status: new
Component: contrib.admin | Version: 1.7
Severity: Normal | Resolution:

Keywords: prepopulated_field | Triage Stage: Accepted
inline add |
Has patch: 0 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 1
-------------------------------------+-------------------------------------
Changes (by bmispelon):

* severity: Release blocker => Normal


Comment:

Hi,

I don't think the `release blocker` status is warranted here since the
regression has been fixed.

Having a testcase for this issue would certainly help moving the ticket
forward if you want to take a crack at it.

Thanks.

--
Ticket URL: <https://code.djangoproject.com/ticket/13068#comment:36>

Django

unread,
May 29, 2020, 7:04:55 AM5/29/20
to django-...@googlegroups.com
#13068: The "Add another [inline object]" javascript doesn't respect
prepopulated_fields settings
-------------------------------------+-------------------------------------
Reporter: hejsan | Owner: Sean
| Brant
Type: Bug | Status: closed
Component: contrib.admin | Version: 1.7
Severity: Normal | Resolution: fixed

Keywords: prepopulated_field | Triage Stage: Accepted
inline add |
Has patch: 1 | Needs documentation: 0

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

* status: new => closed
* needs_better_patch: 1 => 0
* has_patch: 0 => 1
* resolution: => fixed
* needs_tests: 1 => 0


Comment:

Closing as fixed, because a remaining issue for `prepopulated_fields` and
`StackedInline` is handled in #28357.

--
Ticket URL: <https://code.djangoproject.com/ticket/13068#comment:37>

Reply all
Reply to author
Forward
0 new messages