Create Multi Field Component in AEM 6.3 | Community
Skip to main content
AnkurAhlawat-1
Level 6
August 9, 2017

Create Multi Field Component in AEM 6.3

  • August 9, 2017
  • 6 replies
  • 32723 views

[Thread Edited By Adobe]

/*Don’t forget to meet and greet your fellow peers virtually by telling them about yourself here

Go ahead and to it now: https://adobe.ly/3eDnB4v */

 

Actual Post:

The aim of this tutorial is to learn how to create Touch UI Multifield component using HTL formerly known as sightly. As out of the box multifield component has many limitations thanks to ACS common (Adobe consulting services) an open source community for enhancing the existing granite multifield component (granite/ui/components/foundation/form/multifield) that allows developers to create a multifield of a fieldset (group of different fields) .

That’s why we are going to use a ACS common multifield component in this tutorial and show you how to read JSON value saved to the JCR . After completing this tutorial, you will have a clear understanding about:-

  • How to Create Multi Field TouchUI Component in AEM 6.3.
  • How to retrieve values from Multi field dialog.
  • How to retrieve checkbox values from Multi field dialog.
  • Trouble Shooting Multi Field Component in AEM 6.3.

 

Read more at AEMCQ5Tutorials: Create TouchUI Multifield Component using HTL http://www.aemcq5tutorials.com/tutorials/touchui-multifield-component-using-htl/

6 replies

kautuk_sahni
Community Manager
Community Manager
August 9, 2017

One more community use-case got covered by this. Really Nice!!

~kautuk

Kautuk Sahni
susheel
Level 5
August 9, 2017

I think it would be easier to do with JS api in few lines of code.

Coral UI multifield dialog

<?xml version="1.0" encoding="UTF-8"?>

<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"

    jcr:primaryType="nt:unstructured"

    jcr:title="List Collection"

    sling:resourceType="cq/gui/components/authoring/dialog">

    <content

        jcr:primaryType="nt:unstructured"

        sling:resourceType="granite/ui/components/coral/foundation/container">

        <items jcr:primaryType="nt:unstructured">

            <tabs

                jcr:primaryType="nt:unstructured"

                sling:resourceType="granite/ui/components/coral/foundation/tabs"

                maximized="{Boolean}true">

                <items jcr:primaryType="nt:unstructured">

                    <Basic

                        jcr:primaryType="nt:unstructured"

                        jcr:title="Basic"

                        sling:resourceType="granite/ui/components/coral/foundation/fixedcolumns"

                        margin="{Boolean}false">

                        <items jcr:primaryType="nt:unstructured">

                            <column

                                jcr:primaryType="nt:unstructured"

                                sling:resourceType="granite/ui/components/coral/foundation/container">

                                <items jcr:primaryType="nt:unstructured">

                                    <multifieldcollection

                                        jcr:primaryType="nt:unstructured"

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

                                        composite="{Boolean}true"

                                        fieldDescription="Click + to add a new page"

                                        fieldLabel="Multifield collection"

                                        name="./multiCol">

                                        <field

                                            jcr:primaryType="nt:unstructured"

                                            sling:resourceType="granite/ui/components/coral/foundation/container"

                                            name="./items1">

                                            <items jcr:primaryType="nt:unstructured">

                                                <linkurl

                                                    jcr:primaryType="nt:unstructured"

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

                                                    fieldDescription="Select Link Path"

                                                    fieldLabel="Link Url"

                                                    name="./linkUrl"/>

                                                <enterlinktext

                                                    jcr:primaryType="nt:unstructured"

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

                                                    fieldDescription="Enter Link Text"

                                                    fieldLabel="Enter link text"

                                                    name="./linkText"/>

                                            </items>

                                        </field>

                                    </multifieldcollection>

                                    <multifieldcollection1

                                        jcr:primaryType="nt:unstructured"

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

                                        composite="{Boolean}true"

                                        fieldDescription="Click + to add a new page"

                                        fieldLabel="Multifield collection"

                                        name="./multiCol1">

                                        <field

                                            jcr:primaryType="nt:unstructured"

                                            sling:resourceType="granite/ui/components/coral/foundation/container"

                                            name="./items2">

                                            <items jcr:primaryType="nt:unstructured">

                                                <linkurl

                                                    jcr:primaryType="nt:unstructured"

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

                                                    fieldDescription="Select Link Path"

                                                    fieldLabel="Link Url"

                                                    name="./linkUrl"/>

                                                <enterlinktext

                                                    jcr:primaryType="nt:unstructured"

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

                                                    fieldDescription="Enter Link Text"

                                                    fieldLabel="Enter link text"

                                                    name="./linkText"/>

                                            </items>

                                        </field>

                                    </multifieldcollection1>

                                </items>

                            </column>

                        </items>

                    </Basic>

                </items>

            </tabs>

        </items>

    </content>

</jcr:root>

JS Api : listcollection.js

"use strict";

use(["/libs/sightly/js/3rd-party/q.js"], function (Q) {

    var childProperties = Q.defer();

    granite.resource.resolve(granite.resource.path + "/" + this.multifieldName).then(function (currentResource) {

        currentResource.getChildren().then(function(child) {

        childProperties.resolve(child);

    });

});

    return childProperties.promise;

});

Sightly: listcollection.html

<sly data-sly-use.listUse="${'listcollection.js' @ multifieldName='items1'}">

  <ul data-sly-list="${listUse}">

    <li><a href="${item.properties.linkUrl}">${item.properties.linkText}</a></li>

  </ul>

</sly>

<sly data-sly-use.listUse="${'listcollection.js' @ multifieldName='items2'}">

  <ul data-sly-list="${listUse}">

    <li><a href="${item.properties.linkUrl}">${item.properties.linkText}</a></li>

  </ul>

</sly>

Level 3
September 27, 2017

Hi thank you for this, im actually using this right now

Can i ask where does it store its values when you used that on your template?

I created my template at /conf/wknd/settings/wcm/templates/wknd/structure/jcr:content/root/header

December 19, 2017

Another easy way to create a multifield is the generic multifield by namics, see GitHub - namics/aem-generic-multifield: Generic Mulifield for AEM​.

AnkurAhlawat-1
Level 6
December 19, 2017

From AEM 6.2 classic ui is deprecated and we don't encourage using jsp and scriplets. Try to update your code using HTL.

edubey
Level 10
December 19, 2017

the one create by

July 29, 2018
July 30, 2018
June 21, 2023

Can we add a custom component as an item in multifield such that when we click on add button, the component gets added?