Opened 16 years ago

Closed 16 years ago

Last modified 13 years ago

#8194 closed (fixed)

Admin form keyboard focus does not respect fields or fieldsets options

Reported by: mdhancher Owned by: nobody
Component: contrib.admin Version: dev
Severity: Keywords: newforms-admin
Cc: ciantic@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

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 (4)

8298.patch (983 bytes ) - added by Fred Bartle <fredbartle@…> 16 years ago.
sets focus to first field in admin
8298.2.patch (982 bytes ) - added by Fred Bartle <fredbartle@…> 16 years ago.
8194_against_8630.diff (982 bytes ) - added by Fred Bartle 16 years ago.
8194_against_8752.diff (441 bytes ) - added by Fred Bartle 16 years ago.
Allows access to BoundField

Download all attachments as: .zip

Change History (13)

comment:1 by Brian Rosner, 16 years ago

milestone: 1.0
Triage Stage: UnreviewedAccepted

by Fred Bartle <fredbartle@…>, 16 years ago

Attachment: 8298.patch added

sets focus to first field in admin

comment:2 by Fred Bartle <fredbartle@…>, 16 years ago

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

by Fred Bartle <fredbartle@…>, 16 years ago

Attachment: 8298.2.patch added

comment:3 by Fred Bartle <fredbartle@…>, 16 years ago

Fixed a typo in the first patch.

comment:4 by Jari Pennanen, 16 years ago

Cc: ciantic@… added
Keywords: newforms-admin added

comment:5 by Fred Bartle, 16 years ago

Has patch: set

Suppose I should check this box!

by Fred Bartle, 16 years ago

Attachment: 8194_against_8630.diff added

comment:6 by Jacob, 16 years ago

Resolution: fixed
Status: newclosed

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

comment:7 by Fred Bartle, 16 years ago

Patch needs improvement: set
Resolution: fixed
Status: closedreopened

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?

by Fred Bartle, 16 years ago

Attachment: 8194_against_8752.diff added

Allows access to BoundField

comment:8 by Jacob, 16 years ago

Resolution: fixed
Status: reopenedclosed

(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.

comment:9 by Jacob, 13 years ago

milestone: 1.0

Milestone 1.0 deleted

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