From 55a05e46fe219ccb483c69434df8f967da2095fb Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Tue, 17 Nov 2026 21:47:46 +0100 Subject: [PATCH] fix(submit): restore the draft of a form opened from the navigation Opening a form from the navigation while the submit view of another form is shown, or while a submission is edited, restored the draft from the local storage before the form was loaded, which failed, so the draft only showed after a reload. The draft is now restored once the form is loaded, unless another form was opened in the meantime. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Andy Scherzinger --- playwright/e2e/edit-submission.spec.ts | 37 ++++++++++++++++++++++++++ playwright/e2e/submit-form.spec.ts | 28 +++++++++++++++++++ src/views/Submit.vue | 9 ++++--- 3 files changed, 71 insertions(+), 3 deletions(-) diff --git a/playwright/e2e/edit-submission.spec.ts b/playwright/e2e/edit-submission.spec.ts index 2fa21ad1e1..2c478f6fbd 100644 --- a/playwright/e2e/edit-submission.spec.ts +++ b/playwright/e2e/edit-submission.spec.ts @@ -86,4 +86,41 @@ test.describe('Edit submission', () => { await submitView.submit() await expect(submitView.successMessage).toBeVisible() }) + + test('The draft of a form opened from the navigation while editing a submission is restored', async ({ + page, + appNavigation, + form, + topBar, + resultsView, + submitView, + }) => { + const resultsUrl = page.url().replace(/\/submit.*$/, '/results') + await appNavigation.clickNewForm() + await expect(form.titleField).toHaveValue('') + await form.fillTitle('Draft form') + await form.addQuestion(QuestionType.ShortAnswer) + const questions = await form.getQuestions() + await questions[0].fillTitle('Pet name') + await topBar.toggleView(FormsView.View) + await submitView.fillText('Pet name', 'Rex') + + page.once('dialog', (dialog) => dialog.accept()) + await page.goto(resultsUrl) + await resultsView.switchToResponses() + await resultsView.editSubmission() + await expect( + await submitView.getGridCellInput('Skills matrix', 'Beginner', 'Python'), + ).toBeChecked() + await appNavigation.getOwnForm('Draft form').click() + await page + .getByRole('dialog', { name: 'Leave form' }) + .getByRole('button', { name: 'Leave' }) + .click() + + await expect( + submitView.getQuestion('Pet name').getByRole('textbox'), + ).toHaveValue('Rex') + await expect(page.getByRole('dialog', { name: 'Clear form' })).toHaveCount(0) + }) }) diff --git a/playwright/e2e/submit-form.spec.ts b/playwright/e2e/submit-form.spec.ts index aa0b666a9f..1104ccb9eb 100644 --- a/playwright/e2e/submit-form.spec.ts +++ b/playwright/e2e/submit-form.spec.ts @@ -67,6 +67,34 @@ test.describe('Form submission', () => { await expect(submitView.successMessage).toBeVisible() }) + test('The draft of a form opened from the navigation is restored', async ({ + page, + appNavigation, + form, + topBar, + submitView, + }) => { + const submitUrl = page.url().replace(/\/edit$/, '/submit') + await appNavigation.clickNewForm() + await expect(form.titleField).toHaveValue('') + await form.fillTitle('Draft form') + await form.addQuestion(QuestionType.ShortAnswer) + const questions = await form.getQuestions() + await questions[0].fillTitle('Pet name') + await topBar.toggleView(FormsView.View) + await submitView.fillText('Pet name', 'Rex') + + page.once('dialog', (dialog) => dialog.accept()) + await page.goto(submitUrl) + await expect(submitView.getQuestion('Your name')).toBeVisible() + await appNavigation.getOwnForm('Draft form').click() + + await expect( + submitView.getQuestion('Pet name').getByRole('textbox'), + ).toHaveValue('Rex') + await expect(page.getByRole('dialog', { name: 'Clear form' })).toHaveCount(0) + }) + test('Partial submission succeeds when no fields are required', async ({ topBar, submitView, diff --git a/src/views/Submit.vue b/src/views/Submit.vue index 4dc3246694..cf3b9af9bd 100644 --- a/src/views/Submit.vue +++ b/src/views/Submit.vue @@ -636,7 +636,7 @@ export default defineComponent({ */ function initFromLocalStorage(): void { const savedState = getFormValuesFromLocalStorage() - if (!savedState) { + if (!savedState || !props.form.questions) { return } @@ -1141,7 +1141,7 @@ export default defineComponent({ watch( () => props.hash, - (): void => { + async (hash: string): Promise => { // If public view, abort. Should normally not occur. if (props.publicView) { logger.error('Hash changed on public view. Aborting.') @@ -1149,7 +1149,10 @@ export default defineComponent({ } resetData() // Fetch full form on change - void viewForm.fetchFullForm(props.form.id) + await viewForm.fetchFullForm(props.form.id) + if (hash !== props.hash) { + return + } initFromLocalStorage() SetWindowTitle(viewForm.formTitle.value) },