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 
41 lines
1.2 KiB
TypeScript
41 lines
1.2 KiB
TypeScript
export const autosaveCollectionSlug = 'autosave-posts'
|
|
|
|
export const autosaveWithValidateCollectionSlug = 'autosave-with-validate-posts'
|
|
|
|
export const customIDSlug = 'custom-ids'
|
|
|
|
export const draftCollectionSlug = 'draft-posts'
|
|
|
|
export const draftWithValidateCollectionSlug = 'draft-with-validate-posts'
|
|
export const draftWithMaxCollectionSlug = 'draft-with-max-posts'
|
|
|
|
export const postCollectionSlug = 'posts'
|
|
|
|
export const diffCollectionSlug = 'diff'
|
|
export const mediaCollectionSlug = 'media'
|
|
|
|
export const versionCollectionSlug = 'version-posts'
|
|
|
|
export const disablePublishSlug = 'disable-publish'
|
|
|
|
export const disablePublishGlobalSlug = 'disable-publish-global'
|
|
|
|
export const collectionSlugs = [
|
|
autosaveCollectionSlug,
|
|
draftCollectionSlug,
|
|
postCollectionSlug,
|
|
diffCollectionSlug,
|
|
mediaCollectionSlug,
|
|
versionCollectionSlug,
|
|
]
|
|
|
|
export const autoSaveGlobalSlug = 'autosave-global'
|
|
export const draftGlobalSlug = 'draft-global'
|
|
export const draftWithMaxGlobalSlug = 'draft-with-max-global'
|
|
|
|
export const globalSlugs = [autoSaveGlobalSlug, draftGlobalSlug]
|
|
|
|
export const localizedCollectionSlug = 'localized-posts'
|
|
|
|
export const localizedGlobalSlug = 'localized-global'
|