Opened 2 years ago

Closed 2 years ago

#33394 closed Cleanup/optimization (invalid)

Adding inlines doesn't work with a manually crafted HTML.

Reported by: Maxim Danilov Owned by: nobody
Component: contrib.admin Version: 4.0
Severity: Normal Keywords: admin, modeladmin, inline, inline.js
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

We have a very old bug in inlines.js from django\contrib\admin\static\admin\js.

error in inlines.js from row 327, method document.onready

How to reproduce:

  1. Create admin form with any inline.
  2. Open change form in browser, сopy whole html tag with class=".js-inline-admin-formset" and with childs.
  3. Override admin/change_form.html and add copy html part from 2. before admin form. Of cause all "id" in tags should be unique.

Now every time if change_form is opened, inlines.js made wrong add_new_inline_object link.

Why:
in inlines.js any methods stackedFormset or tabularFormset don't check "id" from formset and add link to any formset with childs with class "...-group" and ".inline-related".

Has Patch: yes.

//  django\contrib\admin\static\admin\js\inlines.js
// row 335:
$(selector).stackedFormset(selector, inlineOptions.options);
// change to 
$(this).find("[id^=" + inlineOptions.name.substring(1) + "-]").stackedFormset(selector, inlineOptions.options);

// rows 338-339:
selector = inlineOptions.name + "-group .tabular.inline-related tbody:first > tr.form-row";
$(selector).tabularFormset(selector, inlineOptions.options);
// change to 
selector = inlineOptions.name + "-group .tabular.inline-related tbody:first > tr[id^=" + inlineOptions.name.substring(1) + "-].form-row ";
$(this).children().tabularFormset(selector, inlineOptions.options);

I only add "id" from every inline in jquery selector.

This is not impossible situation, i include additional inline for my needs directly in html, and founded this bug.

Change History (3)

comment:1 by Mariusz Felisiak, 2 years ago

Has patch: unset
Resolution: invalid
Status: newclosed
Summary: inlines.js error in django.contrib.admin since Django 1.xxAdding inlines doesn't work with a manually crafted HTML.
Type: BugCleanup/optimization

This is not impossible situation, i include additional inline for my needs directly in html, and founded this bug.

Thanks for the report, however I don't think it's something that we would like (or need) to support.

comment:2 by Maxim Danilov, 2 years ago

Resolution: invalid
Status: closednew

inline.js has a bug: document.onready add link to wrong html tag.
It can be reproduced, and it has patch.

Why it should be not changed?

comment:3 by Mariusz Felisiak, 2 years ago

Resolution: invalid
Status: newclosed

Because, as far as I'm aware it's not a supported scenario. If you can provide a sample project that reproduces this issue without steps based on manual modification of the generated HTML, then we can reconsider this decision.

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