fix(ui): issues with prevent leave and autosave when the form is submitted but invalid (#11233)
Fixes https://github.com/payloadcms/payload/issues/11224 Fixes https://github.com/payloadcms/payload/issues/10492 This PR fixes a few weird behaviours when `validate: true` is set on drafts: - when autosave is on and you submit an invalid form it would get stuck in an infinite loop - PreventLeave would not trigger for submitted but invalid forms leading to potential data loss Changes: - Adds e2e tests for the above scenarios - Adds a new `isValid` flag on the `Form` context provider to signal globally if the form is in a valid or invalid state - Components like Autosave will manage this internally since it manages its own submission flow as well - Adds PreventLeave to Autosave too for when form is invalid meaning data hasn't been actually saved so we want to prevent the user accidentally losing data by reloading or closing the page The following tests have been added 
This commit is contained in:
@@ -7,7 +7,12 @@ import type { DraftPost } from './payload-types.js'
|
||||
import { devUser } from '../credentials.js'
|
||||
import { executePromises } from '../helpers/executePromises.js'
|
||||
import { titleToDelete } from './shared.js'
|
||||
import { diffCollectionSlug, draftCollectionSlug, mediaCollectionSlug } from './slugs.js'
|
||||
import {
|
||||
autosaveWithValidateCollectionSlug,
|
||||
diffCollectionSlug,
|
||||
draftCollectionSlug,
|
||||
mediaCollectionSlug,
|
||||
} from './slugs.js'
|
||||
import { textToLexicalJSON } from './textToLexicalJSON.js'
|
||||
|
||||
const filename = fileURLToPath(import.meta.url)
|
||||
@@ -120,6 +125,13 @@ export async function seed(_payload: Payload, parallel: boolean = false) {
|
||||
draft: true,
|
||||
})
|
||||
|
||||
await _payload.create({
|
||||
collection: autosaveWithValidateCollectionSlug,
|
||||
data: {
|
||||
title: 'Initial seeded title',
|
||||
},
|
||||
})
|
||||
|
||||
const diffDoc = await _payload.create({
|
||||
collection: diffCollectionSlug,
|
||||
locale: 'en',
|
||||
|
||||
Reference in New Issue
Block a user