Skip to content

Commit

Permalink
FORMS-16201 Register auto save in publish(disabled) mode only
Browse files Browse the repository at this point in the history
  • Loading branch information
girotraapankaj committed Sep 22, 2024
1 parent e1a2739 commit e254049
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -373,4 +373,10 @@ public String getName() {
return FormContainer.super.getName();
}

@JsonIgnore
@Override
public AutoSaveConfiguration getAutoSaveConfig() {
return autoSaveConfig;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -362,4 +362,9 @@ default void visit(Consumer<ComponentExporter> callback) throws Exception {}
default String getParentPagePath() {
return null;
}

@JsonIgnore
default AutoSaveConfiguration getAutoSaveConfig() {
return null;

Check warning on line 368 in bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/models/form/FormContainer.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L368 was not covered by tests
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand All @@ -96,6 +96,10 @@
}
}
}

#getAutoSaveAttribute() {
return this.getFormElement()?.getAttribute('data-cmp-auto-save') === 'true';
}
}

async function onDocumentReady() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand All @@ -61,4 +62,4 @@
</div>
</form>
<div data-cmp-adaptiveform-container-loader="${container.id}"></div>
</sly>
</sly>

0 comments on commit e254049

Please sign in to comment.