Expand my Community achievements bar.

SOLVED

Is there a OOTB way to fetch values of dialog fields in the same dialog xml?

Avatar

Level 7

In the component cq:dialog, I want to fetch the value of a dropdown field and store it into another dialog field node.
For example : 

                                     <content-type
                                        jcr:primaryType="nt:unstructured"
                                        sling:resourceType="granite/ui/components/coral/foundation/form/select"
                                        fieldDescription="Content Type for content"
                                        name="./jcr:content/metadata/content-type"
                                        multiple="{Boolean}true"
                                        granite:id="seeAlso"
                                        fieldLabel="Content Type">
                                    <datasource
                                            jcr:primaryType="nt:unstructured"
                                            sling:resourceType="project/utilities/dialog/datasource"
                                            dataType="content-type"
                                            sort="{Boolean}true"
                                            path="/content/project/global/reference-data/metadata/content-type"/>
                                </content-type>
                                <usedIn-container
                                    granite:id="seeAlso"
                                    jcr:primaryType="nt:unstructured"
                                    jcr:title="Select to include"
                                    sling:resourceType="granite/ui/components/coral/foundation/form/fieldset"
                                    bottomDescription="select as required">
                                    <items jcr:primaryType="nt:unstructured">
                                        <header
                                            jcr:primaryType="nt:unstructured"
                                            sling:resourceType="project/components/commons/see-also/note"
                                            note="Title|Content ID|Topic Path|Last Published Date"/>
                                        <used-in
                                            jcr:primaryType="nt:unstructured"
                                            sling:resourceType="dam/gui/components/admin/schemafield"
                                            fieldLabel="Used In"
                                            name="./jcr:content/metadata/usedIn"
                                            contentType=*here I want to store value of above content type dropdown*
                                            resourceType="project/components/commons/see-also/checkboxgroup">
                                            <datasource
                                                jcr:primaryType="nt:unstructured"
                                                sling:resourceType="/bin/project/getTopicReferences"/>
                                        </used-in>
                                    </items>
                                </usedIn-container>


In above component xml, I want to store value of dropdown content-type in used-in node.

I want to know if there exists an OOTB way to do this within the xml.

I am not looking for solutions via javascript.

 

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

You need to try like below

 

Field from where the value needs to be copied

arunpatidar_2-1705588345001.png


Field where the value needs to be copied

arunpatidar_1-1705588316365.png

 

corresponding hidden field for @valueFrom

arunpatidar_3-1705588399403.png

 

After saving the dialog

 

arunpatidar_0-1705588261134.png
opening the dialog

arunpatidar_4-1705588433576.png

 

 



Arun Patidar

View solution in original post

5 Replies

Avatar

Level 7

@Kamal_Kishor  I checked with @ValueFrom
But it doesn't seem to work.
Below is the code for the same.

 

<used-in
     jcr:primaryType="nt:unstructured"
     sling:resourceType="dam/gui/components/admin/schemafield"
     fieldLabel="Used In"
     name="./jcr:content/metadata/usedIn"
     contentType="./jcr:content/metadata/contentType@ValueFrom"
     resourceType="project/components/commons/see-also/checkboxgroup">
      <datasource
           jcr:primaryType="nt:unstructured"
           sling:resourceType="/bin/project/getTopicReferences"/>
</used-in>

 


I also tried with 

contentType="jcr:content/metadata/contentType@ValueFrom"
But this doesn't work as well.
Can you tell if I am doing something wrong?

 

Avatar

Level 9

@pulkitvashisth : @ValueFrom has to be applied in name field.

 

Something like this for example:
<field1
.....
    fieldLabel="Field 1"
    name="./field1"/>
<field2
.....
    name="./field2@ValueFrom"
    value="./field1"
    defaultValue="./field1"/>

This will store the value from 'field1' in 'field2' when you save the component dialog. 
You can try with simple textfield first to see that it works. Later you can try it with drop-down field values. Also, don't skip the defaultValue as that seems to be required (you can try with and without it to see quickly).

 

Avatar

Correct answer by
Community Advisor

You need to try like below

 

Field from where the value needs to be copied

arunpatidar_2-1705588345001.png


Field where the value needs to be copied

arunpatidar_1-1705588316365.png

 

corresponding hidden field for @valueFrom

arunpatidar_3-1705588399403.png

 

After saving the dialog

 

arunpatidar_0-1705588261134.png
opening the dialog

arunpatidar_4-1705588433576.png

 

 



Arun Patidar

Avatar

Community Advisor

No, there is no out-of-the-box way to do that as far as i know (i might be wrong).

All the information from the dialog is only available in the FrontEnd until you submit it. After this, the information gets stored in nodes. So, if you need to use the data which is not yet stored in JCR, you need to use JavaScript to accommodate your other dialogs' components.

This approach is usually used to hide/show other elements or to populate other dropdowns. You can check references here:

Hope this helps.



Esteban Bustamante