* 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.
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>
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>
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>
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>
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>
* 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>
* needs_tests: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/13068#comment:28>
* 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>
* 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>
* 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>
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>
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>
* 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>
* 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>
* 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>