Opened 12 years ago

Closed 12 years ago

#18420 closed Uncategorized (fixed)

JavaScript crashes in django admin for translation inlines in some circumstances

Reported by: maciej.maciaszek@… Owned by: nobody
Component: contrib.admin Version: 1.4
Severity: Normal Keywords: javascript
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


This issue is close to #10651.

I use here FeinCMS but I'm sure it's Django bug not Feincms bug.

Models of my app integrated as Aplication Content look like:

class Plant(models.Model, TranslatedObjectMixin):

    class Meta:
        verbose_name = _('Performance')

class PlantTranslation(Translation(Plant)):
    title = models.CharField(max_length=255, verbose_name=_('Performance Title'))
    slug = models.SlugField()
    description = models.TextField(max_length=2000)

    class Meta:
        verbose_name = _('Peformance Translation')

    def __unicode__(self):
        return '%s' % (self.title,)

class PlantAdmin(admin.ModelAdmin):
    inlines = [admin_translationinline(PlantTranslation)]

As you can see in django admin I only have inline forms for each translation because translated object itself doesn't have any fields.

JavaScript crashes at django/contrib/admin/templates/admin/change_form.html on line 70.

It renders this line as:

<script type="text/javascript">document.getElementById("").focus();</script>

so I get an JS error. It would be nice that JS check first if there's existing field which it can focus on.

Attachments (2)

django_admin_first_field_focus.diff (743 bytes ) - added by maciej.maciaszek@… 12 years ago.
django_admin_first_field_focus.2.diff (747 bytes ) - added by maciej.maciaszek@… 12 years ago.
fixed diff

Download all attachments as: .zip

Change History (4)

by maciej.maciaszek@…, 12 years ago

comment:1 by Keryn Knight <django@…>, 12 years ago

That patch looks like it'll throw a TemplateSyntaxError on the if statement, as the test terminates on 'and' rather than 'and add'

by maciej.maciaszek@…, 12 years ago

fixed diff

comment:2 by Julien Phalip <jphalip@…>, 12 years ago

Resolution: fixed
Status: newclosed

In [d708298184f8e19f250d2cee5bb900e496ed1175]:

Fixed #18420 -- Prevented the admin JS from crashing when the main form contains no field. Thanks to maciej.maciaszek for the report and patch.

Note: See TracTickets for help on using tickets.
Back to Top