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 Jan 16, 2025
1 parent 755d9c7 commit 0f256bb
Show file tree
Hide file tree
Showing 12 changed files with 146 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,9 @@ public String getLanguageDirection() {
}
properties.put(FD_ROLE_ATTRIBUTE, getRoleAttribute());
properties.put(FD_FORM_DATA_ENABLED, formDataEnabled);
properties.put(ReservedProperties.FD_AUTO_SAVE_PROPERTY_WRAPPER, this.autoSaveConfig);
if (this.autoSaveConfig != null && this.autoSaveConfig.isEnableAutoSave()) {
properties.put(ReservedProperties.FD_AUTO_SAVE_PROPERTY_WRAPPER, this.autoSaveConfig);
}
properties.put(FD_CUSTOM_FUNCTIONS_URL, getCustomFunctionUrl());
properties.put(FD_DATA_URL, getDataUrl());

Expand Down Expand Up @@ -416,4 +418,10 @@ public String getCustomFunctionUrl() {
return getContextPath() + ADOBE_GLOBAL_API_ROOT + FORMS_RUNTIME_API_GLOBAL_ROOT + "/customfunctions/" + getId();
}

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -385,4 +385,15 @@ default String getCustomFunctionUrl() {
return null;
}

/**
* Returns the auto save configuration
*
* @return auto save configuration
* @since com.adobe.cq.forms.core.components.models.form 5.11.0
*/
@JsonIgnore
default AutoSaveConfiguration getAutoSaveConfig() {
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
* </p>
*/

@Version("5.10.0")
@Version("5.11.0")
package com.adobe.cq.forms.core.components.models.form;

import org.osgi.annotation.versioning.Version;
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,7 @@
import com.adobe.cq.forms.core.Utils;
import com.adobe.cq.forms.core.components.internal.form.FormConstants;
import com.adobe.cq.forms.core.components.internal.form.ReservedProperties;
import com.adobe.cq.forms.core.components.models.form.FieldType;
import com.adobe.cq.forms.core.components.models.form.FormClientLibManager;
import com.adobe.cq.forms.core.components.models.form.FormContainer;
import com.adobe.cq.forms.core.components.models.form.TextInput;
import com.adobe.cq.forms.core.components.models.form.ThankYouOption;
import com.adobe.cq.forms.core.components.models.form.*;
import com.adobe.cq.forms.core.context.FormsCoreComponentTestContext;
import com.day.cq.i18n.I18n;
import com.day.cq.wcm.api.NameConstants;
Expand Down Expand Up @@ -79,6 +75,8 @@ public class FormContainerImplTest {
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_WITHOUT_FIELDTYPE = CONTENT_ROOT + "/formcontainerv2-without-fieldtype";

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 @@ -244,6 +242,14 @@ void testJSONExport() throws Exception {
Utils.testJSONExport(formContainer, Utils.getTestExporterJSONPath(BASE, PATH_FORM_1));
}

@Test
void testJSONExportWithAutoSaveEnable() 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);
Utils.testJSONExport(formContainer, Utils.getTestExporterJSONPath(BASE, PATH_FORM_WITH_AUTO_SAVE));
}

@Test
void testGetThankYouMessage() throws Exception {
FormContainer formContainer = Utils.getComponentUnderTest(PATH_FORM_1, FormContainer.class, context);
Expand Down Expand Up @@ -555,4 +561,15 @@ void testCustomFunctionUrl() throws Exception {
FormContainer formContainer = Utils.getComponentUnderTest(PATH_FORM_1, FormContainer.class, context);
assertEquals("/adobe/forms/af/customfunctions/L2NvbnRlbnQvZm9ybXMvYWYvZGVtbw==", formContainer.getCustomFunctionUrl());
}

@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());
assertTrue(formContainer.getAutoSaveConfig().isEnableAutoSave());
assertEquals(AutoSaveConfiguration.AutoSaveStrategyType.TIME, formContainer.getAutoSaveConfig().getAutoSaveStrategyType());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
"dorType": "generate",
"dorTemplateRef": "xyz"
},
"fd:autoSave": {
"fd:enableAutoSave":false
},
"fd:path": "/content/forms/af/demo/jcr:content/formcontainerv2",
"fd:isHamburgerMenuEnabled": false,
"fd:schemaType": "BASIC",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"id": "L2NvbnRlbnQvZm9ybXMvYWYvZGVtbw==",
"fieldType": "form",
"lang": "en",
"properties": {
"thankyouPage": "/a/b/c",
"fd:path": "/content/forms/af/demo/jcr:content/formcontainerv2WithAutoSave",
"fd:schemaType": "BASIC",
"fd:isHamburgerMenuEnabled": false,
"fd:roleAttribute": null,
"fd:formDataEnabled": true,
"fd:autoSave": {
"fd:enableAutoSave": true,
"fd:autoSaveStrategyType": "time",
"fd:autoSaveInterval": 2
},
"fd:customFunctionsUrl": "/adobe/forms/af/customfunctions/L2NvbnRlbnQvZm9ybXMvYWYvZGVtbw==",
"fd:dataUrl": "/adobe/forms/af/data/L2NvbnRlbnQvZm9ybXMvYWYvZGVtbw=="
},
"action": "/adobe/forms/af/submit/L2NvbnRlbnQvZm9ybXMvYWYvZGVtbw==",
"events": {
"custom:setProperty": [
"$event.payload"
]
},
":itemsOrder": [
"textinput"
],
"adaptiveform": "0.14.2",
"metadata": {
"grammar": "json-formula-1.0.0",
"version": "1.0.0"
},
":type": "core/fd/components/form/container/v2/container",
":items": {
"textinput": {
"id": "textinput-2ddda8d6f9",
"fieldType": "text-input",
"name": "abc",
"visible": false,
"description": "dummy",
"type": "string",
"label": {
"value": "def",
"visible": true
},
"properties": {
"customProp": "customPropValue",
"fd:dor": {
"dorExclusion": false
},
"fd:path": "/content/forms/af/demo/jcr:content/formcontainerv2WithAutoSave/textinput"
},
"events": {
"custom:setProperty": [
"$event.payload"
]
},
":type": "core/fd/components/form/textinput/v1/textinput"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,16 @@
"prefillService" : "abc",
"fd:enableAutoSave": "true",
"fd:autoSaveInterval": "2",
"fd:autoSaveStrategyType": "time"
"fd:autoSaveStrategyType": "time",
"textinput" : {
"jcr:primaryType": "nt:unstructured",
"sling:resourceType" : "core/fd/components/form/textinput/v1/textinput",
"name" : "abc",
"jcr:title" : "def",
"hideTitle" : false,
"description" : "dummy",
"fd:translationIds" : "{\"jcr:title\":\"guideContainer##textinput##jcr:title##5598\",\"placeholder\":\"guideContainer##textinput##description##5648\"}",
"visible" : false,
"customProp": "customPropValue"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Adaptive Form container written in HTL.
* Thank you page
* Thank you message
* Ability to drop other adaptive form components
* Auto save feature for Drafts

### Use Object
The Adaptive Form Container component uses the `com.adobe.cq.forms.core.components.models.form.FormContainer` Sling Model for its Use-object.
Expand Down Expand Up @@ -88,4 +89,6 @@ Apply a `data-cmp-is="adaptiveFormContainer"` attribute to the `cmp-adaptiveform
Applying `data-cmp-adaptiveform-container-loader` attribute to the div specifically for applying the loader class on it, it is to ensure that the loading icon should not appear over components.

Applying `data-cmp-custom-functions-module-url` attribute to the div to point to the edge delivery URL of the custom functions file. Custom Functions exported from this file will be registered in Function Runtime.
This Url should whitelist the AEM author/publish domain in the Cross Origin Resource Sharing (CORS) configuration.
This Url should whitelist the AEM author/publish domain in the Cross Origin Resource Sharing (CORS) configuration.

Applying `data-cmp-auto-save` attribute to the `cmp-adaptiveform-container` block to control the auto-save functionality. If the attribute's value is set to true, auto-save will be enabled for the form; otherwise, it will not be triggered. This attribute will be set to true in published mode if enableAutoSave is enabled.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,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 @@ -103,6 +103,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 Down Expand Up @@ -76,4 +77,4 @@
</div>
</form>
<div data-cmp-adaptiveform-container-loader="${container.id}"></div>
</sly>
</sly>
32 changes: 16 additions & 16 deletions ui.frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions ui.frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"webpack-merge": "^5.8.0"
},
"dependencies": {
"@aemforms/af-core": "^0.22.112",
"@aemforms/af-formatters": "^0.22.109",
"@aemforms/af-core": "^0.22.114",
"@aemforms/af-formatters": "^0.22.114",
"@aemforms/af-custom-functions": "1.0.13"
}
}

0 comments on commit 0f256bb

Please sign in to comment.