fix: form input not being saved after "back" (#11540)

Co-authored-by: Hariom Balhara <hariombalhara@gmail.com>
This commit is contained in:
Nafees Nazik 2023-09-27 10:09:37 +05:30 committed by GitHub
parent 919066222b
commit ce13350d5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 1 deletions

View File

@ -252,6 +252,23 @@ test.describe("prefill", () => {
});
});
test("Persist the field values when going back and coming back to the booking form", async ({
page,
users,
}) => {
await page.goto("/pro/30min");
await selectFirstAvailableTimeSlotNextMonth(page);
await page.fill('[name="name"]', "John Doe");
await page.fill('[name="email"]', "john@example.com");
await page.fill('[name="notes"]', "Test notes");
await page.click('[data-testid="back"]');
await selectFirstAvailableTimeSlotNextMonth(page);
await expect(page.locator('[name="name"]')).toHaveValue("John Doe");
await expect(page.locator('[name="email"]')).toHaveValue("john@example.com");
await expect(page.locator('[name="notes"]')).toHaveValue("Test notes");
});
test("logged out", async ({ page, users }) => {
await page.goto("/pro/30min");

View File

@ -461,7 +461,10 @@ function useInitialFormValues({
const session = useSession();
useEffect(() => {
(async function () {
if (Object.keys(formValues).length) return formValues;
if (Object.keys(formValues).length) {
setDefaultValues(formValues);
return;
}
if (!eventType?.bookingFields) {
return {};