Expand my Community achievements bar.

How to manage the action settings of a proxy Form Container component?

Avatar

Level 2

I'm using AEM WCM Core Components - Core Form Container (v2).  I have a proxy Form Container where I'm trying to change the fields displayed for the "Mail" Action Type.  See the fields in the red box in the attached screenshot.  Those fields appear to be defined and managed by the datasource at core/wcm/components/form/container/v1/datasource/actionsetting.  However, I can't find where I can override that datasource nor can I find any documentation.  I've looked at FormActionTypeSettingsDataSourceServlet, but that didn't provide any hints.

I want to hide the "From" field using sling:hideResource but still provide a default value from my proxy Form Container.  How would I go about doing that?  Also, my frontend is not sightly, it's Angular.

Snag_bdcd14b.png

Snag_bde938c.png

5 Replies

Avatar

Community Advisor

@dpkhmhs :

 

You can try as below at the text field dialog.

<text

jcr:primaryType="nt:unstructured"

sling:resourceType="granite/ui/components/coral/foundation/form/textfield"

fieldDescription="Value of Product"

fieldLabel="Page value"

sling:hideResource="true"

name="./testValue"/>

<text-default

jcr:primaryType="nt:unstructured"

sling:resourceType="/libs/granite/ui/components/coral/foundation/form/hidden"

name="./testValue@DefaultValue"

value="test"/>

Thanks,
Siva

Avatar

Community Advisor

Hi @dpkhmhs,

Definition of Mail Action Type can be found under /libs/foundation/components/form/actions/mail.

ootb-mail-action.jpg

As you can see, this is marked as granite:FinalArea - which means you can't overlay this - as this is against Adobe best practices. You can read more about this rules under documentation:

What you can do, is simply copy this action into your code base, and do all modifications.

Below I have described step by step what has to be done - we.retail project has been used, but it will be the same for any other project, so you should be able to apply this in yours easily.

  1. Copy entire mail folder from /libs/foundation/components/form/actions/mail to your project under apps. You should see structure like this. In my case using we.retail full path is /apps/weretail/components/form/actions/mail
    action-strucutre.jpg
  2. Navigate to granite:data and change value of showhidetargetvalue property so it correspond location of mail action in your code base. This is important to do this, in other case you will not see any fields in dialog in case you select your custom Action Type.
    from-action-granite-condition.jpg
  3. Now you can do changes in the dialog structure. If you want to get rid off From filed simply remove it from the structure. But you can apply here any changes you need.
    mail-action-form-inputs.jpg

That's all here is a result - I have set title to Mail 2 to recognize which Action Type is mine.

Screenshot 2023-03-19 at 10.16.14.png

Here is also xml structure with all changes that have been described in above steps.

<actions jcr:primaryType="sling:Folder">
    <mail jcr:primaryType="sling:Folder"
        hint="Sends all submitted values in an email."
        jcr:title="Mail 2"
        sling:resourceType="foundation/components/form/action">
        <cq:dialog jcr:primaryType="nt:unstructured" granite:class="action-type-dialog" jcr:title="Form Container"
            sling:resourceType="granite/ui/components/coral/foundation/container">
            <items jcr:primaryType="nt:unstructured">
                <subject jcr:primaryType="nt:unstructured"
                    fieldDescription="Subject line for the emails sent for each submitted form." fieldLabel="Subject"
                    name="./subject" required="true"
                    sling:resourceType="granite/ui/components/coral/foundation/form/textfield" />
                <mailto jcr:primaryType="nt:unstructured"
                    fieldDescription="Email addresses where the messages will be sent." fieldLabel="To"
                    fieldLabel_commentI18n="Context: Email To field" required="true"
                    sling:resourceType="granite/ui/components/coral/foundation/form/multifield">
                    <field jcr:primaryType="nt:unstructured" granite:class="mailto-Textfield" name="./mailto"
                        sling:resourceType="granite/ui/components/coral/foundation/form/textfield" />
                </mailto>
                <cc jcr:primaryType="nt:unstructured"
                    fieldDescription="Email addresses where the messages will be sent as a copy." fieldLabel="CC"
                    sling:resourceType="granite/ui/components/coral/foundation/form/multifield">
                    <field jcr:primaryType="nt:unstructured" name="./cc"
                        sling:resourceType="granite/ui/components/coral/foundation/form/textfield" />
                </cc>
            </items>
            <granite:data jcr:primaryType="nt:unstructured" showhidetargetvalue="weretail/components/form/actions/mail"
                usesRedirect="true" />
        </cq:dialog>
        <dialog jcr:primaryType="cq:WidgetCollection">
            <mailto jcr:primaryType="cq:Widget" fieldLabel="Mailto" name="./mailto" xtype="multifield" />
            <cc jcr:primaryType="cq:Widget" fieldLabel="CC" name="./cc" xtype="multifield" />
            <bcc jcr:primaryType="cq:Widget" fieldLabel="BCC" name="./bcc" xtype="multifield" />
            <subject jcr:primaryType="cq:Widget" fieldLabel="Subject" name="./subject" xtype="textfield" />
        </dialog>
    </mail>
</actions>

Additionally you may also need to made some changes in forward.jsp file which is run to handle this action after form is submitted. You will need to experiment to see if this is needed or not.

Avatar

Level 2

This solution works to hide the 'From' field in your custom Mail type, but it shares its data with the original library's Mail action type. For example, if you choose 'Mail 2' and then add a few items to the 'To' field, and then delete a couple and confirm your changes, when you re-open the authoring dialog you see that both the Mail2 option and the Mail option contain both the items it should (the items from your Mail 2 option), as well as  the items you originally added before deleting items.

 

So if you add items 1,2,3 and then delete option 2, if you submit your changes and then re-open the dialog it contains 1,3,1,2,3 

Avatar

Community Advisor

This, is intended and expected.

It is expected because custom action from my example use exactly the same names in dialog fields like the original Mail action. This is why you see the same values after re-open the dialog.

It was intended, as using the same names will guarantee that structure in the repository will be understandably by OOTB backend code that is provided to handle Mail action. In other words it allows to utilize OOTB backend logic to handle custom action. Please check and compare custom action and OOTB (/libs/foundation/components/form/actions/mail)

Of course this can be easily changed (solved). Simply change the names in dialog definition in your custom action e.g.

Instead:

<subject jcr:primaryType="nt:unstructured"
  fieldDescription="Subject line for the emails sent for each submitted form."
  fieldLabel="Subject"
  name="./subject" required="true"
  sling:resourceType="granite/ui/components/coral/foundation/form/textfield" />

use

<subject jcr:primaryType="nt:unstructured"
  fieldDescription="Subject line for the emails sent for each submitted form."
  fieldLabel="Subject"
  name="./customSubject" required="true"
  sling:resourceType="granite/ui/components/coral/foundation/form/textfield" />

Repeat that for each field, and you will have to apply similar change to every place in custom action that was using the same name value.

Of course this will also require to build custom backend part that will handle the action, because OOTB will not support that.

Above change will solve the case when you see the same values under OOTB Mail action, after putting them in custom one.

You can also consider to hide OOTB Mail action from dropdown using ACLs so it will not be visible to the authors at all.