Opened 7 weeks ago

Closed 7 weeks ago

Last modified 7 weeks ago

#36423 closed Bug (fixed)

Admin form submission via enter will incorrectly select all items from a ToManyField that uses a horizontal display instead of saving the form

Reported by: Blayze Owned by: Blayze
Component: contrib.admin Version: 5.2
Severity: Release blocker Keywords:
Cc: Blayze Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: yes

Description

In Django 5.2, when submitting a form by using the enter button while a input field is active, all items from a many to many list will be selected instead of saving the form. The field must be using the horizontal display via the filter_horizontal for this to happen. If the many to many field is not on the page it will save as expected.

This seems to be happening because the "Choose all X" button does not specify type="button" so it defaults to submit instead.

I believe this is a regression from ticket #34619 where four links were changed to buttons without specifying the type.

Commit: https://github.com/django/django/commit/857b1048d53ebf5fc5581c110e85c212b81ca83a#diff-3c2966b7041905eb8758311f5fedee0454575617ae55cfc7d0e3cc9d03c6671eR70

When I changed the type on all of those buttons to type="button" the page worked as expected.

Change History (9)

comment:1 by Blayze, 7 weeks ago

Has patch: set
Owner: set to Blayze
Status: newassigned

comment:2 by Blayze, 7 weeks ago

I created a small patch for this issue since it was a simple fix. Let me know if you would like anything changed.

https://github.com/django/django/pull/19510

Last edited 7 weeks ago by Blayze (previous) (diff)

comment:3 by Antoliny, 7 weeks ago

Triage Stage: UnreviewedAccepted

Replicated. Thank you for raising this issue.

comment:4 by Antoliny, 7 weeks ago

Severity: NormalRelease blocker

comment:5 by Natalia Bidart, 7 weeks ago

Needs documentation: set
Needs tests: set

comment:6 by Blayze, 7 weeks ago

Needs documentation: unset
Needs tests: unset

comment:7 by Natalia Bidart, 7 weeks ago

Triage Stage: AcceptedReady for checkin

comment:8 by nessita <124304+nessita@…>, 7 weeks ago

Resolution: fixed
Status: assignedclosed

In 9042962:

Fixed #36423 -- Prevented filter_horizontal buttons from intercepting form submission.

In the admin's filter_horizontal widget, optional action buttons like
"Choose all", "Remove all", etc. were changed from <a> to <button>
elements in #34619, but without specifying type="button". As a result,
when pressing Enter while focused on a form input, these buttons could
be triggered and intercept form submission.

Explicitly set type="button" on these control buttons to prevent them
from acting as submit buttons.

Thanks Antoliny Lee for the quick triage and review.

Regression in 857b1048d53ebf5fc5581c110e85c212b81ca83a.

comment:9 by Natalia <124304+nessita@…>, 7 weeks ago

In 37e5cc6:

[5.2.x] Fixed #36423 -- Prevented filter_horizontal buttons from intercepting form submission.

In the admin's filter_horizontal widget, optional action buttons like
"Choose all", "Remove all", etc. were changed from <a> to <button>
elements in #34619, but without specifying type="button". As a result,
when pressing Enter while focused on a form input, these buttons could
be triggered and intercept form submission.

Explicitly set type="button" on these control buttons to prevent them
from acting as submit buttons.

Thanks Antoliny Lee for the quick triage and review.

Regression in 857b1048d53ebf5fc5581c110e85c212b81ca83a.

Backport of 90429625a85f1f77dfea200c91bd2dabab57974f from main.

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