Expand my Community achievements bar.

SOLVED

Multified Component -Default Item

Avatar

Level 4

Hi ,

I am working on Multified Component and would like to know how to set one item as default in the dialog box .So,Author will be able to add multiple field values on selecting the 'Add' option .Please help me with this .

 

Thanks.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi,

This can be achieved by adding a default node structure in component's cq:template node.

http://prashantonkar.blogspot.com/2019/01/composite-components-in-aem-using.html



Arun Patidar

View solution in original post

10 Replies

Avatar

Administrator

Hi @Keerthi97 

Adding the property "value" to your dialogue input fields would be your solution. 
Take a look at the example below:

 

 

<navigationLinks
   jcr:primaryType="nt:unstructured"
   sling:resourceType="granite/ui/components/coral/foundation/form/multifield"
   fieldLabel="Navigation Links">
   <field
      jcr:primaryType="nt:unstructured"
      sling:resourceType="granite/ui/components/coral/foundation/container"
      name="./navLinks">
      <items jcr:primaryType="nt:unstructured">
         <fieldset
            jcr:primaryType="nt:unstructured"
            jcr:title="Link"
            sling:resourceType="granite/ui/components/coral/foundation/form/fieldset">
            <items jcr:primaryType="nt:unstructured">
               <linkLabel
                  jcr:primaryType="nt:unstructured" sling:resourceType="granite/ui/components/coral/foundation/form/textfield"
                  fieldLabel="Link Label"
                  name="./linkLabel"
                  value="@@@@@@@INiTIAL VALUE GOES HERE@@@@@@@@"/>
            </items>
         </fieldset>
      </items>
   </field>
</navigationLinks>

 

HTH



Kautuk Sahni

Avatar

Level 4

Hi @kautuk_sahni ,

Thanks for your response!

 

I tried adding the value property in the input field ,but still it doesn't work.Could you please provide some examples for setting the value property .

 

Thanks in Advance!

Avatar

Community Advisor

@Keerthi97  the example snippet shared by @kautuk_sahni should work, by default you would see it as shown in screenshot 1 and you need to click Add button to see default value(as you can see in Screenshot 2) and save the dialog at least once so that the default data will also get stored.

 

Screenshot 1: 

Siva_Sogalapalli_0-1648030749061.png

Screenshot 2: 

Siva_Sogalapalli_1-1648030773377.png

Hope this helps. 

 

 

Avatar

Level 4

Hi @Siva_Sogalapalli ,

Thanks for your response.

 

Yes , I can able to see the dialog values as shared in the screenshot 1 but my query is to get one item as default when configuring the component without selecting the 'Add' button.Please help me with this.

 

Thanks

Avatar

Community Advisor

I haven't seen such OOTB option or examples, but to make it simple you can write conditions in sling model and use default values if multifield is not configured. 

 

Avatar

Community Advisor

The default values work with new content, not with the existing dragged component. can you try with the new component?



Arun Patidar

Avatar

Level 4

Hi @arunpatidar ,

 Default value is getting reflected but i want to see one field items as default on configuring the dialog and so i can add multiple items by clicking on the 'Add' option.

 

Thanks.

Avatar

Correct answer by
Community Advisor

Hi,

This can be achieved by adding a default node structure in component's cq:template node.

http://prashantonkar.blogspot.com/2019/01/composite-components-in-aem-using.html



Arun Patidar

Avatar

Level 4

Hi @arunpatidar ,

Thanks for your response.

Is there any OOTB component to show one default container on the dialog in the multifield component and able to add multiple values using add option.Please suggest.

 

 

Thanks.

Avatar

Community Advisor

If you are using composite type multifield

 

then your cq:template node should look like below

<?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">
    <items
        jcr:primaryType="nt:unstructured">
        <item0
            jcr:primaryType="nt:unstructured"
            question="val1"/>
    </items>
</jcr:root>

 



Arun Patidar