Skip to content

fix(ui): ask in the page before a link leaves a changed form - #340

Merged
HugoFara merged 2 commits into
developfrom
fix/in-app-unsaved-forms
Nov 4, 2026
Merged

HugoFara merged 2 commits into
developfrom
fix/in-app-unsaved-forms

Conversation

@HugoFara

@HugoFara HugoFara commented Nov 4, 2026

Copy link
Copy Markdown
Owner

Follows the 3.8.1 live test.

In-app prompt on full-page forms

Only term forms used the in-app dialog. On every other form, a plain link such as Cancel fell back to the browser's prompt, which goes against keeping the native one for emergencies.

lwtFormCheck.askBeforeExit() now also installs one click listener on the document. On a changed form, a click on a link that would replace the page opens the in-app dialog. Keeping stays on the form; discarding clears the state and follows the link, so the native prompt does not appear as well.

The listener runs when the click reaches the document, so a link whose own handler cancelled it never asks. It also ignores in-page anchors, new tabs, downloads, non-web links and modified clicks.

The dialog says "this page", with a new dialog.leave_message in all 11 locales, because the existing message says "this term".

The native prompt stays for closing or reloading the tab, and for scripted navigation such as the navbar language picker and the logout form.

langId in the term API

GET /api/v1/terms/{id} returned "langId": {}, because two handlers passed the LanguageId object to the JSON encoder. Both now return the number.

Testing

  • Vitest: 13 new tests for the guard.
  • Cypress, in a real browser: new test on the text form covering keep and discard. Full run: 326 passed, 2 skipped (24-anki-live, no Anki), none failed.
  • PHPUnit, Psalm, PHPCS, typecheck and ESLint pass.
  • The translations are mine and have not been reviewed by native speakers.

Two handlers passed the LanguageId value object straight to the JSON
encoder, so clients received "langId": {}.
Only term forms had the in-app dialog, so every other form fell back to
the browser's prompt on a plain link. A click on a link that would
replace the page now opens the dialog on all of them. The native prompt
stays for what a page cannot intercept: closing or reloading the tab.
@HugoFara
HugoFara merged commit 271a0d4 into develop Nov 4, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant