#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)
Change History (13)
comment:1 by , 16 years ago
milestone: | → 1.0 |
---|---|
Triage Stage: | Unreviewed → Accepted |
by , 16 years ago
Attachment: | 8298.patch added |
---|
comment:2 by , 16 years ago
Added patch that respects fields or fieldsets specified in ModelAdmin. Required access to forms.BoundField.
by , 16 years ago
Attachment: | 8298.2.patch added |
---|
comment:4 by , 16 years ago
Cc: | added |
---|---|
Keywords: | newforms-admin added |
by , 16 years ago
Attachment: | 8194_against_8630.diff added |
---|
comment:6 by , 16 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:7 by , 16 years ago
Patch needs improvement: | set |
---|---|
Resolution: | fixed |
Status: | closed → reopened |
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?
comment:8 by , 16 years ago
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
sets focus to first field in admin