diff --git a/django/contrib/admin/templates/admin/change_form.html b/django/contrib/admin/templates/admin/change_form.html
index 8f8dfe6..fb278b4 100644
a
|
b
|
|
17 | 17 | {% block breadcrumbs %}{% if not is_popup %} |
18 | 18 | <div class="breadcrumbs"> |
19 | 19 | <a href="../../../">{% trans "Home" %}</a> › |
20 | | <a href="../../">{{ app_label|capfirst|escape }}</a> › |
21 | | {% if has_change_permission %}<a href="../">{{ opts.verbose_name_plural|capfirst }}</a>{% else %}{{ opts.verbose_name_plural|capfirst }}{% endif %} › |
| 20 | <a href="../../">{{ app_label|capfirst|escape }}</a> › |
| 21 | {% if has_change_permission %}<a href="../">{{ opts.verbose_name_plural|capfirst }}</a>{% else %}{{ opts.verbose_name_plural|capfirst }}{% endif %} › |
22 | 22 | {% if add %}{% trans "Add" %} {{ opts.verbose_name }}{% else %}{{ original|truncatewords:"18" }}{% endif %} |
23 | 23 | </div> |
24 | 24 | {% endif %}{% endblock %} |
… |
… |
|
60 | 60 | {% submit_row %} |
61 | 61 | |
62 | 62 | {% if adminform and add %} |
63 | | <script type="text/javascript">document.getElementById("{{ adminform.first_field.auto_id }}").focus();</script> |
| 63 | <script type="text/javascript">document.getElementById("{{ adminform.first_field.id_for_label }}").focus();</script> |
64 | 64 | {% endif %} |
65 | 65 | |
66 | 66 | {# JavaScript for prepopulated fields #} |
diff --git a/django/forms/forms.py b/django/forms/forms.py
index 1cf6f2a..f776861 100644
a
|
b
|
class BoundField(StrAndUnicode):
|
522 | 522 | return self.html_name |
523 | 523 | return '' |
524 | 524 | auto_id = property(_auto_id) |
| 525 | |
| 526 | def _id_for_label(self): |
| 527 | """ |
| 528 | Wrapper around the field widget's `id_for_label` class method. |
| 529 | Useful, for example, for focusing on this field regardless of whether |
| 530 | it has a single widget or a MutiWidget. |
| 531 | """ |
| 532 | widget = self.field.widget |
| 533 | id_ = widget.attrs.get('id') or self.auto_id |
| 534 | return widget.id_for_label(id_) |
| 535 | id_for_label = property(_id_for_label) |
diff --git a/tests/regressiontests/admin_views/models.py b/tests/regressiontests/admin_views/models.py
index 02c6b92..60319ea 100644
a
|
b
|
class Answer(models.Model):
|
666 | 666 | def __unicode__(self): |
667 | 667 | return self.answer |
668 | 668 | |
| 669 | class Reservation(models.Model): |
| 670 | start_date = models.DateTimeField() |
| 671 | price = models.IntegerField() |
| 672 | |
669 | 673 | admin.site.register(Article, ArticleAdmin) |
670 | 674 | admin.site.register(CustomArticle, CustomArticleAdmin) |
671 | 675 | admin.site.register(Section, save_as=True, inlines=[ArticleInline]) |
… |
… |
admin.site.register(PlotDetails)
|
701 | 705 | admin.site.register(CyclicOne) |
702 | 706 | admin.site.register(CyclicTwo) |
703 | 707 | admin.site.register(WorkHour, WorkHourAdmin) |
| 708 | admin.site.register(Reservation) |
704 | 709 | |
705 | 710 | # We intentionally register Promo and ChapterXtra1 but not Chapter nor ChapterXtra2. |
706 | 711 | # That way we cover all four cases: |
diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py
index f392393..d4d58a2 100644
a
|
b
|
class AdminViewBasicTest(TestCase):
|
431 | 431 | except SuspiciousOperation: |
432 | 432 | self.fail("Filters should be allowed if they are defined on a ForeignKey pointing to this model") |
433 | 433 | |
| 434 | class AdminJavaScriptTest(AdminViewBasicTest): |
| 435 | def testSingleWidgetFirsFieldFocus(self): |
| 436 | """ |
| 437 | JavaScript-assisted auto-focus on first field. |
| 438 | """ |
| 439 | response = self.client.get('/test_admin/%s/admin_views/picture/add/' % self.urlbit) |
| 440 | self.assertContains( |
| 441 | response, |
| 442 | '<script type="text/javascript">document.getElementById("id_name").focus();</script>' |
| 443 | ) |
| 444 | |
| 445 | def testMultiWidgetFirsFieldFocus(self): |
| 446 | """ |
| 447 | JavaScript-assisted auto-focus should work if a model/ModelAdmin setup |
| 448 | is such that the first form field has a MultiWidget. |
| 449 | """ |
| 450 | response = self.client.get('/test_admin/%s/admin_views/reservation/add/' % self.urlbit) |
| 451 | self.assertContains( |
| 452 | response, |
| 453 | '<script type="text/javascript">document.getElementById("id_start_date_0").focus();</script>' |
| 454 | ) |
| 455 | |
| 456 | |
434 | 457 | class SaveAsTests(TestCase): |
435 | 458 | fixtures = ['admin-views-users.xml','admin-views-person.xml'] |
436 | 459 | |