diff --git a/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/internal/models/v2/form/FormContainerImpl.java b/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/internal/models/v2/form/FormContainerImpl.java index ed89546728..2fbd3cba43 100644 --- a/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/internal/models/v2/form/FormContainerImpl.java +++ b/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/internal/models/v2/form/FormContainerImpl.java @@ -373,4 +373,10 @@ public String getName() { return FormContainer.super.getName(); } + @JsonIgnore + @Override + public AutoSaveConfiguration getAutoSaveConfig() { + return autoSaveConfig; + } + } diff --git a/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/models/form/FormContainer.java b/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/models/form/FormContainer.java index 71e8c53fa7..7f9807881a 100644 --- a/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/models/form/FormContainer.java +++ b/bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/models/form/FormContainer.java @@ -362,4 +362,9 @@ default void visit(Consumer callback) throws Exception {} default String getParentPagePath() { return null; } + + @JsonIgnore + default AutoSaveConfiguration getAutoSaveConfig() { + return null; + } } diff --git a/bundles/af-core/src/test/java/com/adobe/cq/forms/core/components/internal/models/v2/form/FormContainerImplTest.java b/bundles/af-core/src/test/java/com/adobe/cq/forms/core/components/internal/models/v2/form/FormContainerImplTest.java index 9edf57eb1c..72f2102285 100644 --- a/bundles/af-core/src/test/java/com/adobe/cq/forms/core/components/internal/models/v2/form/FormContainerImplTest.java +++ b/bundles/af-core/src/test/java/com/adobe/cq/forms/core/components/internal/models/v2/form/FormContainerImplTest.java @@ -75,6 +75,8 @@ public class FormContainerImplTest { private static final String CONTENT_ROOT = CONTENT_PAGE_ROOT + "/jcr:content"; private static final String CONTENT_DAM_ROOT = "/content/dam/formsanddocuments/demo"; private static final String PATH_FORM_1 = CONTENT_ROOT + "/formcontainerv2"; + + private static final String PATH_FORM_WITH_AUTO_SAVE = CONTENT_ROOT + "/formcontainerv2WithAutoSave"; private static final String PATH_FORM_1_WITHOUT_REDIRECT = CONTENT_ROOT + "/formcontainerv2WithoutRedirect"; private static final String CONTENT_FORM_WITHOUT_PREFILL_ROOT = "/content/forms/af/formWithoutPrefill"; private static final String PATH_FORM_WITHOUT_PREFILL = CONTENT_FORM_WITHOUT_PREFILL_ROOT + "/formcontainerv2WithoutPrefill"; @@ -477,4 +479,12 @@ public void testGetLanguageDirection() throws Exception { assertEquals("ltr", formContainer.getLanguageDirection()); } + @Test + public void testGetAutoSaveProperties() throws Exception { + context.load().json(BASE + "/test-content-auto-save.json", PATH_FORM_WITH_AUTO_SAVE); + FormContainer formContainer = Utils.getComponentUnderTest(PATH_FORM_WITH_AUTO_SAVE, + FormContainer.class, context); + assertNotNull(formContainer.getAutoSaveConfig()); + } + } diff --git a/ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/container/v2/container/clientlibs/site/js/formcontainerview.js b/ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/container/v2/container/clientlibs/site/js/formcontainerview.js index 826fb80cf5..3492e0eaaf 100644 --- a/ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/container/v2/container/clientlibs/site/js/formcontainerview.js +++ b/ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/container/v2/container/clientlibs/site/js/formcontainerview.js @@ -81,7 +81,7 @@ */ #setupAutoSave(formModel) { const autoSaveProperties = formModel?.properties?.['fd:autoSave']; - const enableAutoSave = autoSaveProperties?.['fd:enableAutoSave']; + const enableAutoSave = this.#getAutoSaveAttribute(); if (enableAutoSave) { const autoSaveStrategyType = autoSaveProperties['fd:autoSaveStrategyType']; const autoSaveInterval = autoSaveProperties['fd:autoSaveInterval']; @@ -96,6 +96,10 @@ } } } + + #getAutoSaveAttribute() { + return this.getFormElement()?.getAttribute('data-cmp-auto-save') === 'true'; + } } async function onDocumentReady() { diff --git a/ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/container/v2/container/container.html b/ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/container/v2/container/container.html index 633e8d2c55..c3fe8f99bd 100644 --- a/ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/container/v2/container/container.html +++ b/ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/container/v2/container/container.html @@ -36,6 +36,7 @@ data-sly-use.templates="core/wcm/components/commons/v1/templates.html" action="${container.metadata.action}" id="${container.id}" + data-cmp-auto-save="${wcmmode.disabled && container.autoSaveConfig && container.autoSaveConfig.enableAutoSave ? 'true' : 'false'}" data-cmp-is="adaptiveFormContainer" data-cmp-context-path="${request.contextPath}" data-cmp-page-lang="${container.containingPageLang}" @@ -61,4 +62,4 @@
- \ No newline at end of file +