aem-core-forms-components icon indicating copy to clipboard operation
aem-core-forms-components copied to clipboard

Rule Editor and "is submitted successfully" event on "FORM"

Open kisonay opened this issue 1 year ago • 6 comments

Expected Behaviour

I expect to be able to create a container level rule via the rule editor, particularly when a form is successfully submitted.

Actual Behaviour

The rule editor cannot be invoked on the form container. When you enter the rule editor via a different component and select "FORM", making changes fail.

Steps to Reproduce

Navigate to a form based on af core components, enter the rule editor and try to create a rule at the "FORM" level with the event of "is submitted successfully", click done and view the console.

Platform and Version

Core Components Version: 2.24.2 Core Form Components: 1.1.32

AEM Version (mention the exact version in case of cloud SDK)

6.5.18

AEM Forms Version

6.0.1016

Sample Code that illustrates the problem

Logs taken while reproducing problem

When you get into the rule editor and configure a rule on the form container, when clicking done, you see the following error in the console:

authoring.min.js:516 Uncaught 
TypeError: Cannot read properties of undefined (reading 'startsWith')
    at authoring.min.js:516:33
    at lodash.min.js:55:41
    at wa (lodash.min.js:36:14)
    at lodash.min.js:54:347
    at Function.nf (lodash.min.js:77:7)
    at preparePostData (authoring.min.js:506:15)
    at saveScript (authoring.min.js:573:24)
    at authoring.min.js:442:9
    at Object.saveModel (authoring.min.js:605:60)
    at Object.saveHandler (authoring.min.js:1186:69)

After further investigation, the event being invoked is as follows:

{
    "Successful Submission": {
        "content": [
            "upper(language.$value)"
        ]
    }
}

But when we take a look at the clientlib, /libs/fd/af-expeditor/clientlibs/authoring/js/RuleSaveHandler.js, we see "Successful Submission" missing from the eventMapping

const AFStorageSettings = {
        AF1 : {
            copyright: true,
            saveScripts: false,
            eventMapping: RuntimeUtil.EVENT_PROPERTY_MAPPING,
            scriptMerger: guidelib.author.scriptMerger,
            deleteLegacyProperties : true,
            multipleEvents : false,
            saveValidationStatus: false
        },
        AF2 : {
            copyright: false,
            saveScripts: true,
            multipleEvents : true,
            eventMapping: {
                'Visibility' : 'visible',
                'Calculate' : 'value',
                "Enabled" : "enabled",
                'Value Commit' : 'event:change',
                'Initialize' : 'event:initialize',
                'Click' : 'event:click',
                'Validate' : 'validationExpression'
            },
            ...
        }
    }

With the mapping missing, the following code (starting on line 122) causes "name" to be undefined causing the error and preventing the rule from being processed.

 if (storageSettings.saveScripts) {
            ...
            _.each(allEvents, function (script, evntName) {
                let name;
                if (storageSettings.multipleEvents && evntName.startsWith('custom:')) {
                    name = "event:custom_" + evntName.substring('custom:'.length)
                } else {
                    name = storageSettings.eventMapping[evntName]
                }
                ...
            });

kisonay avatar Jun 21 '24 21:06 kisonay

@arunattri26 Could you take a look at this issue ?

rismehta avatar Jun 24 '24 05:06 rismehta

Hi @kisonay, I have verified that it is a bug. We will fix it.

arunattri26 avatar Jul 03 '24 08:07 arunattri26

Hi @arunattri26 Could you please share the progress of that ticket and the fix ETA? Thank you in advance.

katerynababynina avatar Oct 09 '24 13:10 katerynababynina

It is my understanding that the fix will be included in SP22.

kisonay avatar Oct 09 '24 14:10 kisonay

@arunattri26 the fix of saving the rule on successfulSubmission works but the rule action is not triggered on that event.

I checked the code of core-forms-components-all-1.1.54 FormContainer v2 logic /apps/core/fd/components/form/container/v2/container/clientlibs/site/js/formcontainerview.js and it doesn't contain a "submitSuccess" code where the state.events.submitSuccess is true and the rule code is executed. Can you please check that? Thank you.

katerynababynina avatar Oct 15 '24 14:10 katerynababynina

The fix is part of SP22. Please raise a hotfix request for an earlier Service Pack if required.

arunattri26 avatar Feb 06 '25 06:02 arunattri26