Expand my Community achievements bar.

Submissions are now open for the 2026 Adobe Experience Maker Awards.
SOLVED

How to set default value for dropdown granite/ui/components/coral/foundation/form/select

Avatar

Level 2

I am trying to set the default value for dropdown : granite/ui/components/coral/foundation/form/select

 

But it's not working tried with selected = "true",forceIgnoreFreshness = "true"

Kirthika_0-1748932245148.png

Anyone please suggets!

1 Accepted Solution

Avatar

Correct answer by
Community Advisor
4 Replies

Avatar

Correct answer by
Community Advisor

Avatar

Community Advisor

you can try like this to set default value:

 

<items jcr:primaryType="nt:unstructured">
    <dropdown
        jcr:primaryType="nt:unstructured"
        sling:resourceType="granite/ui/components/coral/foundation/form/select"
        fieldLabel="Select an Option"
        name="./dropdownValue"
        value="option2"> <!-- Default value -->
        <items jcr:primaryType="nt:unstructured">
            <option1
                jcr:primaryType="nt:unstructured"
                text="Option 1"
                value="option1" />
            <option2
                jcr:primaryType="nt:unstructured"
                text="Option 2"
                value="option2" />
            <option3
                jcr:primaryType="nt:unstructured"
                text="Option 3"
                value="option3" />
        </items>
    </dropdown>
</items>

Avatar

Community Advisor

Hi @Kirthika 

 

Below fix will work if selected option is applied as suggested by arun --

 

 

PRATHYUSHA_VP_0-1748950942613.png

PRATHYUSHA_VP_1-1748951003079.png

 

Thanks

Avatar

Community Advisor

Hi @Kirthika ,

 

Option 1: Use value Property

Set the default selected option using the value property on the select component.

Example:

<dropdown
    jcr:primaryType="nt:unstructured"
    sling:resourceType="granite/ui/components/coral/foundation/form/select"
    fieldLabel="Choose an Option"
    name="./dropdownValue"
    value="option2"> <!-- Default selected value -->
    <items jcr:primaryType="nt:unstructured">
        <option1
            jcr:primaryType="nt:unstructured"
            text="Option 1"
            value="option1"/>
        <option2
            jcr:primaryType="nt:unstructured"
            text="Option 2"
            value="option2"/>
        <option3
            jcr:primaryType="nt:unstructured"
            text="Option 3"
            value="option3"/>
    </items>
</dropdown>

This will show Option 2 as selected by default when the dialog opens for the first time.

 

Option 2: Use selected="true" on the Option

If you're not using the value property, you can directly mark an <option> as selected:

Example:

<dropdown
    jcr:primaryType="nt:unstructured"
    sling:resourceType="granite/ui/components/coral/foundation/form/select"
    fieldLabel="Choose an Option"
    name="./dropdownValue">
    <items jcr:primaryType="nt:unstructured">
        <option1
            jcr:primaryType="nt:unstructured"
            text="Option 1"
            value="option1"/>
        <option2
            jcr:primaryType="nt:unstructured"
            text="Option 2"
            value="option2"
            selected="true"/> <!-- This is selected by default -->
        <option3
            jcr:primaryType="nt:unstructured"
            text="Option 3"
            value="option3"/>
    </items>
</dropdown>

Noted:

  - selected="true" works only when no value is already stored in the JCR node (i.e., fresh content).

  - value="option2" always works unless overridden by existing saved value in the content node.

  - If you're using editable templates, ensure this dialog is part of a component not pre-authored with existing values (check /content/...).

 

Regards,
Amit