Opened 8 years ago

Closed 8 years ago

#2410 closed enhancement (fixed)

[patch] Add id attribute to change list form to easily look up it in javascript.

Reported by: Alex Dedul Owned by: adrian
Component: contrib.admin Version:
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


Title says it all. One thing this patch changes more is opts.object_name.lower to opts.module_name in bodyclass block, because opts.module_name is exactly opts.object_name.lower.

Index: django/contrib/admin/templates/admin/change_form.html
--- django/contrib/admin/templates/admin/change_form.html   (revision 3439)
+++ django/contrib/admin/templates/admin/change_form.html   (working copy)
@@ -6,8 +6,8 @@
 {% endblock %}
 {% block stylesheet %}{% admin_media_prefix %}css/forms.css{% endblock %}
 {% block coltype %}{% if ordered_objects %}colMS{% else %}colM{% endif %}{% endblock %}
-{% block bodyclass %}{{ opts.app_label }}-{{ opts.object_name.lower }} change-form{% endblock %}
+{% block bodyclass %}{{ opts.app_label }}-{{ opts.module_name }} change-form{% endblock %}
 {% block breadcrumbs %}{% if not is_popup %}
 <div class="breadcrumbs">
      <a href="../../../">{% trans "Home" %}</a> &rsaquo;
@@ -18,10 +18,9 @@
   {% if has_absolute_url %}<li><a href="../../../r/{{ content_type_id }}/{{ object_id }}/" class="viewsitelink">{% trans "View on site" %}</a></li>{% endif%}
 {% endif %}{% endif %}
-<form {% if has_file_field %}enctype="multipart/form-data" {% endif %}action="{{ form_url }}" method="post">{% block form_top %}{% endblock %}
+<form {% if has_file_field %}enctype="multipart/form-data" {% endif %}action="{{ form_url }}" method="post" id="id_{{ opts.module_name }}_form">{% block form_top %}{% endblock %}
 {% if is_popup %}<input type="hidden" name="_popup" value="1" />{% endif %}
 {% if opts.admin.save_on_top %}{% submit_row %}{% endif %}

Attachments (0)

Change History (2)

comment:1 Changed 8 years ago by Alex Dedul

Form could be accessed and as document.forms[0], but that looks a bit obscure, accessing by id is cleaner.

comment:2 Changed 8 years ago by adrian

  • Resolution set to fixed
  • Status changed from new to closed

(In [3568]) Fixed #2410 -- Added HTML ID attribute to <form> on admin change-list pages, for easy targetting with JavaScript and CSS

Add Comment

Modify Ticket

Change Properties
<Author field>
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.