diff --git a/CHANGELOG.md b/CHANGELOG.md index 0335353c4cc..78ea7ef6ce8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,7 @@ - Migrated the reassign entries, replace relations, and replace references modals to the Form API. ([#19589](https://github.com/craftcms/cms/pull/19589)) - Restored Score sorting for element index searches and preserved previous sort fields as tie-breakers. ([#19731](https://github.com/craftcms/cms/pull/19731)) - Fixed a bug where the Edit and View bulk actions did nothing on element indexes. ([#19747](https://github.com/craftcms/cms/pull/19747)) +- Fixed a bug where failed settings saves could lose input and validation errors when a successful save would redirect to another page. ([#19775](https://github.com/craftcms/cms/pull/19775)) - Fixed a bug where money inputs could be hidden within fields or submit their values under the wrong name. ([#19767](https://github.com/craftcms/cms/pull/19767)) - Fixed a bug where visually-hidden labels, headings, and status messages were visible on some control panel pages. - Fixed a bug where `` fields with a `maxlength` weren’t sized to fit it, which made the element index pagination’s page input overlap the “Next page” button. diff --git a/resources/js/common/types/index.ts b/resources/js/common/types/index.ts index f1bfea19e5d..f3492504d2e 100644 --- a/resources/js/common/types/index.ts +++ b/resources/js/common/types/index.ts @@ -231,7 +231,7 @@ export type ActionItems = Array; export interface FormSaveOptions { redirect?: boolean; data?: FormValues; - preserveState?: boolean; + preserveState?: boolean | 'errors'; } export interface EntryType { diff --git a/resources/js/modules/settings/composables/useSettingsSave.ts b/resources/js/modules/settings/composables/useSettingsSave.ts index d8609c92dfe..643ded59766 100644 --- a/resources/js/modules/settings/composables/useSettingsSave.ts +++ b/resources/js/modules/settings/composables/useSettingsSave.ts @@ -113,7 +113,8 @@ export function useSettingsSave( data: extraData = {}, // Reset page state when this screen sends the user elsewhere, while saves // that remain on the current screen keep their local state by default. - preserveState = !(redirect && redirectUrl.value), + // Validation failures preserve input and errors instead of remounting. + preserveState = redirect && redirectUrl.value ? 'errors' : true, }: FormSaveOptions = {}) { options.onBeforeSave?.();