Opened 4 years ago

Closed 4 years ago

#31483 closed Cleanup/optimization (fixed)

Remove admin change_form.js dependency on jQuery.

Reported by: Jon Dufresne Owned by: Jon Dufresne
Component: contrib.admin Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

https://github.com/django/django/blob/3.0/django/contrib/admin/static/admin/js/change_form.js

The file currently uses jQuery for two purposes:

  1. To add an onclick handler to elements with the add-another class. This event handler has been unused since 07988744b347302925bc6cc66511e34224db55ab (Django 1.8) when the class was removed. Rather than porting and maintaining this code block, it can be removed.
  1. To find the first visible, enabled input and then focus it. This code is simple enough to port.

Change History (4)

comment:2 by Mariusz Felisiak, 4 years ago

Owner: changed from nobody to Jon Dufresne
Status: newassigned
Triage Stage: UnreviewedAccepted

comment:3 by Carlton Gibson <carlton@…>, 4 years ago

In a8bb53db:

Refs #31483 -- Removed CSS and JavaScript for unused HTML class add-another.

The HTML class was removed in 07988744b347302925bc6cc66511e34224db55ab.
As such, the CSS and JavaScript is unused.

comment:4 by Carlton Gibson <carlton@…>, 4 years ago

Resolution: fixed
Status: assignedclosed

In f27482f1:

Fixed #31483 -- Rewrote change_form.js without jQuery.

The use of $(document).ready() was removed. The script is loaded at the
end of the document. Therefore, the referenced DOM elements are already
available and the script does not need to wait for the full DOM to be
ready before continuing.

Now that the script has no external dependencies, it can be loaded
asynchronously. As such, the async attribute was added to the script
element.

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