Hi,
I'm currently looking into using a JSON file to set choices for a dropdown field in a metadata schema. For the basic approach, the answer from @lukasz-m in json for dropdown field in AEM Metadata Schema has already helped me a lot.
My follow up question would be: Is it possible to set default values using JSON?
The reason I'm asking is that I would like to have more than one default option selected when using a multivalue dropdown. As far as I can tell, this is not possible in the UI.
You can, however, do so by manually assigning the key value pair "selected" = "true" in CRXDE Lite. See the picture below for an example.
=>
When dealing with a larger set of data, it would be more comfortable to use a JSON for generating these choices and setting the default values. But currently, I cannot see how I would approach the later part.
I tried using "selected = true" in the JSON:
But while the options are generated correctly, no default is being set.
In summary: How do I go about setting default choices in the JSON file for a dropwdown field in a metadata schema?
Best Regards,
Lukas
Solved! Go to Solution.
Views
Replies
Total Likes
Maybe in Adobe Experience Manager (AEM), setting default values for a dropdown field in a metadata schema using a JSON file is not directly supported. The JSON file is primarily used to define the available choices for the dropdown, but it does not handle default selections.
To set default values for a dropdown field in a metadata schema, you would need to utilize other AEM capabilities, such as custom code or scripts. Here's a possible approach:
Here's an example of how you could implement this:
<myDropdown
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/select"
fieldLabel="My Dropdown Field"
name="./myDropdown"
cq:listeners="[ready: function() { myNamespace.setDefaultValues(this); }]"
options="load">
<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" />
...
</items>
</myDropdown>
var myNamespace = myNamespace || {};
myNamespace.setDefaultValues = function (dropdown) {
// Set the default values in the dropdown field
dropdown.setValue(["option1", "option2"]);
};
You can have a try with this. Thanks.
Maybe in Adobe Experience Manager (AEM), setting default values for a dropdown field in a metadata schema using a JSON file is not directly supported. The JSON file is primarily used to define the available choices for the dropdown, but it does not handle default selections.
To set default values for a dropdown field in a metadata schema, you would need to utilize other AEM capabilities, such as custom code or scripts. Here's a possible approach:
Here's an example of how you could implement this:
<myDropdown
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/select"
fieldLabel="My Dropdown Field"
name="./myDropdown"
cq:listeners="[ready: function() { myNamespace.setDefaultValues(this); }]"
options="load">
<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" />
...
</items>
</myDropdown>
var myNamespace = myNamespace || {};
myNamespace.setDefaultValues = function (dropdown) {
// Set the default values in the dropdown field
dropdown.setValue(["option1", "option2"]);
};
You can have a try with this. Thanks.
Since drop-down value coming from json are not visible in metadata form location setting the default option as select twill not work OOTB with values coming from json.
if you still want to achieve this then you need to do your custom implementation. Check this for reference https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/display-default-text-on-dr...
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies