Skip to content

Commit e254049

Browse files
FORMS-16201 Register auto save in publish(disabled) mode only
1 parent e1a2739 commit e254049

File tree

5 files changed

+28
-2
lines changed

5 files changed

+28
-2
lines changed

bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/internal/models/v2/form/FormContainerImpl.java

+6
Original file line numberDiff line numberDiff line change
@@ -373,4 +373,10 @@ public String getName() {
373373
return FormContainer.super.getName();
374374
}
375375

376+
@JsonIgnore
377+
@Override
378+
public AutoSaveConfiguration getAutoSaveConfig() {
379+
return autoSaveConfig;
380+
}
381+
376382
}

bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/models/form/FormContainer.java

+5
Original file line numberDiff line numberDiff line change
@@ -362,4 +362,9 @@ default void visit(Consumer<ComponentExporter> callback) throws Exception {}
362362
default String getParentPagePath() {
363363
return null;
364364
}
365+
366+
@JsonIgnore
367+
default AutoSaveConfiguration getAutoSaveConfig() {
368+
return null;
369+
}
365370
}

bundles/af-core/src/test/java/com/adobe/cq/forms/core/components/internal/models/v2/form/FormContainerImplTest.java

+10
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ public class FormContainerImplTest {
7575
private static final String CONTENT_ROOT = CONTENT_PAGE_ROOT + "/jcr:content";
7676
private static final String CONTENT_DAM_ROOT = "/content/dam/formsanddocuments/demo";
7777
private static final String PATH_FORM_1 = CONTENT_ROOT + "/formcontainerv2";
78+
79+
private static final String PATH_FORM_WITH_AUTO_SAVE = CONTENT_ROOT + "/formcontainerv2WithAutoSave";
7880
private static final String PATH_FORM_1_WITHOUT_REDIRECT = CONTENT_ROOT + "/formcontainerv2WithoutRedirect";
7981
private static final String CONTENT_FORM_WITHOUT_PREFILL_ROOT = "/content/forms/af/formWithoutPrefill";
8082
private static final String PATH_FORM_WITHOUT_PREFILL = CONTENT_FORM_WITHOUT_PREFILL_ROOT + "/formcontainerv2WithoutPrefill";
@@ -477,4 +479,12 @@ public void testGetLanguageDirection() throws Exception {
477479
assertEquals("ltr", formContainer.getLanguageDirection());
478480
}
479481

482+
@Test
483+
public void testGetAutoSaveProperties() throws Exception {
484+
context.load().json(BASE + "/test-content-auto-save.json", PATH_FORM_WITH_AUTO_SAVE);
485+
FormContainer formContainer = Utils.getComponentUnderTest(PATH_FORM_WITH_AUTO_SAVE,
486+
FormContainer.class, context);
487+
assertNotNull(formContainer.getAutoSaveConfig());
488+
}
489+
480490
}

ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/container/v2/container/clientlibs/site/js/formcontainerview.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
*/
8282
#setupAutoSave(formModel) {
8383
const autoSaveProperties = formModel?.properties?.['fd:autoSave'];
84-
const enableAutoSave = autoSaveProperties?.['fd:enableAutoSave'];
84+
const enableAutoSave = this.#getAutoSaveAttribute();
8585
if (enableAutoSave) {
8686
const autoSaveStrategyType = autoSaveProperties['fd:autoSaveStrategyType'];
8787
const autoSaveInterval = autoSaveProperties['fd:autoSaveInterval'];
@@ -96,6 +96,10 @@
9696
}
9797
}
9898
}
99+
100+
#getAutoSaveAttribute() {
101+
return this.getFormElement()?.getAttribute('data-cmp-auto-save') === 'true';
102+
}
99103
}
100104

101105
async function onDocumentReady() {

ui.af.apps/src/main/content/jcr_root/apps/core/fd/components/form/container/v2/container/container.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
data-sly-use.templates="core/wcm/components/commons/v1/templates.html"
3737
action="${container.metadata.action}"
3838
id="${container.id}"
39+
data-cmp-auto-save="${wcmmode.disabled && container.autoSaveConfig && container.autoSaveConfig.enableAutoSave ? 'true' : 'false'}"
3940
data-cmp-is="adaptiveFormContainer"
4041
data-cmp-context-path="${request.contextPath}"
4142
data-cmp-page-lang="${container.containingPageLang}"
@@ -61,4 +62,4 @@
6162
</div>
6263
</form>
6364
<div data-cmp-adaptiveform-container-loader="${container.id}"></div>
64-
</sly>
65+
</sly>

0 commit comments

Comments
 (0)