From e919aedcec0b4b2e230ec688a2a77ce4093bda50 Mon Sep 17 00:00:00 2001 From: forgejo-backport-action Date: Wed, 1 Apr 2026 08:13:12 +0200 Subject: [PATCH] [v15.0/forgejo] fix: allow modals to be submitted multiple times (#11931) **Backport:** https://codeberg.org/forgejo/forgejo/pulls/11843 Fixes #11842. The `once: true` was likely added to prevent multiple concurrent submissions of the same form. This could still be worth preventing, but I suspect it would require wrapping the supplied `onApprove` callback with the corresponding logic, implemented manually, as I am not aware of any native API to prevent concurrent executions of callbacks. ## Checklist ### Tests for JavaScript changes - I added test coverage for JavaScript changes... - [ ] in `web_src/js/*.test.js` if it can be unit tested. - [x] in `tests/e2e/*.test.e2e.js` if it requires interactions with a live Forgejo server (see also the [developer guide for JavaScript testing](https://codeberg.org/forgejo/forgejo/src/branch/forgejo/tests/e2e/README.md#end-to-end-tests)). ### Documentation - [ ] I created a pull request [to the documentation](https://codeberg.org/forgejo/docs) to explain to Forgejo users how to use this change. - [x] I did not document these changes and I do not expect someone else to do it. ### Release notes - [x] This change will be noticed by a Forgejo user or admin (feature, bug fix, performance, etc.). I suggest to include a release note for this change. - [ ] This change is not visible to a Forgejo user or admin (refactor, dependency upgrade, etc.). I think there is no need to add a release note for this change. Co-authored-by: Antonin Delpeuch Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/11931 Reviewed-by: Mathieu Fenniak Co-authored-by: forgejo-backport-action Co-committed-by: forgejo-backport-action --- tests/e2e/repo-labels.test.e2e.ts | 20 ++++++++++++++++++++ web_src/js/modules/modal.ts | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/tests/e2e/repo-labels.test.e2e.ts b/tests/e2e/repo-labels.test.e2e.ts index ef33e91dda..956c4c19d5 100644 --- a/tests/e2e/repo-labels.test.e2e.ts +++ b/tests/e2e/repo-labels.test.e2e.ts @@ -41,3 +41,23 @@ test('Edit label', async ({page}) => { await expect(page.locator('.label-title').filter({hasText: labelName})).toBeVisible(); }); + +test('New label after a failed validation', async ({page}) => { + // for issue https://codeberg.org/forgejo/forgejo/issues/11842 + const response = await page.goto('/user2/repo1/labels'); + expect(response?.status()).toBe(200); + + await page.getByRole('button', {name: 'New label'}).click(); + await expect(page.locator('#new-label-modal')).toBeVisible(); + + // attempt to submit the form without having filled it first + await page.getByRole('button', {name: 'Create label'}).click(); + await screenshot(page, page.locator('#new-label-modal')); + + // then fill the form and submit it again + const labelName = dynamic_id(); + await page.getByRole('textbox', {name: 'Label name'}).fill(labelName); + await page.getByRole('button', {name: 'Create label'}).click(); + + await expect(page.locator('.label-title').filter({hasText: labelName})).toBeVisible(); +}); diff --git a/web_src/js/modules/modal.ts b/web_src/js/modules/modal.ts index 290dccee70..b6fef12b2b 100644 --- a/web_src/js/modules/modal.ts +++ b/web_src/js/modules/modal.ts @@ -13,7 +13,7 @@ export function showModal(modalID: string, onApprove: () => void) { modal.querySelector('.cancel')?.addEventListener('click', () => { modal.close(); }, {once: true, passive: true}); - modal.querySelector('.ok')?.addEventListener('click', onApprove, {once: true, passive: true}); + modal.querySelector('.ok')?.addEventListener('click', onApprove, {passive: true}); // The modal is ready to be shown. modal.showModal();