Django

Code

Ticket #8194 (closed: fixed)

Opened 4 months ago

Last modified 3 months ago

Admin form keyboard focus does not respect fields or fieldsets options

Reported by: mdhancher Assigned to: nobody
Milestone: 1.0 Component: django.contrib.admin
Version: SVN Keywords: newforms-admin
Cc: ciantic@mbnet.fi Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 1

Description

When you re-order the fields in an admin add form using the fields or fieldsets options in your ModelAdmin class, the initial keyboard focus in the admin add/change form does not respect it.

The keyboard focus is set by a JavaScript call to document.getElementById("id_foo").focus(), where the ID is specified in the change_form.html template as {{adminform.first_field.auto_id}}. So an underlying issue is that AdminForm.first_field() (in contrib/admin/options.py) does not respect the re-ordering. I am experiencing this using the current Subversion HEAD, revision 8272.

For example, consider this simple model in models.py:

class MyModel(models.Model):
    foo = models.CharField(max_length=255)
    bar = models.CharField(max_length=255)

and this simple admin configuration in admin.py:

class MyModelAdmin(admin.ModelAdmin):
    fields = ('bar', 'foo')

admin.site.register(MyModel,MyModelAdmin)

Then try to add a new MyModel object using the admin interface, and notice that they keyboard focus starts out at the bottom rather than the top of the form.

Attachments

8298.patch (1.0 kB) - added by Fred Bartle <fredbartle@gmail.com> on 08/11/08 08:44:05.
sets focus to first field in admin
8298.2.patch (1.0 kB) - added by Fred Bartle <fredbartle@gmail.com> on 08/11/08 08:48:14.
8194_against_8630.diff (1.0 kB) - added by fredbartle on 08/27/08 11:12:07.
8194_against_8752.diff (441 bytes) - added by fredbartle on 08/30/08 21:39:36.
Allows access to BoundField?

Change History

08/09/08 20:25:52 changed by brosner

  • needs_better_patch changed.
  • needs_docs changed.
  • stage changed from Unreviewed to Accepted.
  • needs_tests changed.
  • milestone set to 1.0.

08/11/08 08:44:05 changed by Fred Bartle <fredbartle@gmail.com>

  • attachment 8298.patch added.

sets focus to first field in admin

08/11/08 08:45:54 changed by Fred Bartle <fredbartle@gmail.com>

Added patch that respects fields or fieldsets specified in ModelAdmin?. Required access to forms.BoundField?.

08/11/08 08:48:14 changed by Fred Bartle <fredbartle@gmail.com>

  • attachment 8298.2.patch added.

08/11/08 08:49:00 changed by Fred Bartle <fredbartle@gmail.com>

Fixed a typo in the first patch.

08/18/08 14:28:06 changed by Ciantic

  • cc set to ciantic@mbnet.fi.
  • keywords set to newforms-admin.

08/25/08 11:01:02 changed by fredbartle

  • has_patch set to 1.

Suppose I should check this box!

08/27/08 11:12:07 changed by fredbartle

  • attachment 8194_against_8630.diff added.

08/28/08 15:48:59 changed by jacob

  • status changed from new to closed.
  • resolution set to fixed.

(In [8681]) Fixed #8194: AdminForm.first_field now correctly returns the first field when using custom field orders.

08/30/08 21:39:03 changed by fredbartle

  • status changed from closed to reopened.
  • needs_better_patch set to 1.
  • resolution deleted.

I'm reopening because forms.BoundField? is not accessible for this patch to work. As of r8681, if admin fields or fieldsets are specified, the following html is created from the template:

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

Using a try/except block around L25 in django/contrib/admin/helpers.py shows an AttributeError? being raised.

'module' object has no attribute 'BoundField'

Just a side question here, I'm listed under AUTHORS as 'hambaloney' for another ticket I was involved with, is it possible to change that to my name?

08/30/08 21:39:36 changed by fredbartle

  • attachment 8194_against_8752.diff added.

Allows access to BoundField?

08/31/08 15:30:56 changed by jacob

  • status changed from reopened to closed.
  • resolution set to fixed.

(In [8774]) Fixed #8194 (again): correctly focus on the first declared field in the admin. Thanks to fredbartle for catching my silly mistake the first time 'round.


Add/Change #8194 (Admin form keyboard focus does not respect fields or fieldsets options)




Change Properties
Action