diff options
| author | Blayze <blayze@carstickers.com> | 2025-05-28 11:22:29 -0700 |
|---|---|---|
| committer | Natalia <124304+nessita@users.noreply.github.com> | 2025-06-02 22:26:36 -0300 |
| commit | 37e5cc6d89b4653f05a1a00af2eb2187c907c935 (patch) | |
| tree | d77f60c4709a6419e8702f3653be7f2ffe07f005 /tests/admin_widgets | |
| parent | e107b8a9d39ec58a5cadcaf100128ae20b1e052c (diff) | |
[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.
Diffstat (limited to 'tests/admin_widgets')
| -rw-r--r-- | tests/admin_widgets/tests.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/admin_widgets/tests.py b/tests/admin_widgets/tests.py index 74fc30a706..7720ec04c0 100644 --- a/tests/admin_widgets/tests.py +++ b/tests/admin_widgets/tests.py @@ -1740,6 +1740,48 @@ class HorizontalVerticalFilterSeleniumTests(AdminWidgetSeleniumTestCase): self.assertCountSeleniumElements("#id_students_to > option", 2) + def test_form_submission_via_enter_key_with_filter_horizontal(self): + """ + The main form can be submitted correctly by pressing the enter key. + There is no shadowing from other buttons inside the form. + """ + from selenium.webdriver.common.by import By + from selenium.webdriver.common.keys import Keys + + self.school.students.set([self.peter]) + self.school.alumni.set([self.lisa]) + + self.admin_login(username="super", password="secret", login_url="/") + self.selenium.get( + self.live_server_url + + reverse("admin:admin_widgets_school_change", args=(self.school.id,)) + ) + + self.wait_page_ready() + self.select_option("#id_students_from", str(self.lisa.id)) + self.selenium.find_element(By.ID, "id_students_add").click() + self.select_option("#id_alumni_from", str(self.peter.id)) + self.selenium.find_element(By.ID, "id_alumni_add").click() + + # Trigger form submission via Enter key on a text input field. + name_input = self.selenium.find_element(By.ID, "id_name") + name_input.click() + name_input.send_keys(Keys.ENTER) + + # Form was submitted, success message should be shown. + self.wait_for_text( + "li.success", "The school “School of Awesome” was changed successfully." + ) + + # Changes should be stored properly in the database. + school = School.objects.get(id=self.school.id) + self.assertSequenceEqual( + school.students.all().order_by("name"), [self.lisa, self.peter] + ) + self.assertSequenceEqual( + school.alumni.all().order_by("name"), [self.lisa, self.peter] + ) + @ignore_warnings(category=RemovedInDjango60Warning) class AdminRawIdWidgetSeleniumTests(AdminWidgetSeleniumTestCase): |
