Add selected as true to dynamic dropdown | Community
Skip to main content
Shubham_borole
New Participant
Feb 3, 2020 8:28 PM UTC
Solved

Add selected as true to dynamic dropdown

Hello All, I am trying to follow https://helpx.adobe.com/experience-manager/using/creating-touchui-dynamic.html and able to get the dynamic dropdown. However if I want to have a second dropdown value as selected I am unable to do so. Am I missing something?

 

I am trying following

DataSource ds = new SimpleDataSource(new TransformIterator(languages.keySet().iterator(), new Transformer() { public Object transform(Object o) { String language = (String) o; ValueMap vm = new ValueMapDecorator(new HashMap<String, Object>()); vm.put("value", language); vm.put("text", languages.get(language)); //my custom if(selctedLanguage==true) { vm.put("selected", true); } return new ValueMapResource(resolver, new ResourceMetadata(), "nt:unstructured", vm); } }));

. Still the drop down values show as top one selected. 

 

cc @arunpatidar I have looked at aem63app-repo/dynamic-dropdown.js at master · arunpatidar02/aem63app-repo · GitHub but I want to achieve this when I am populating the second dropdown via datasource. Using a ./hiddenproperty did not work for me...

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Shubham_borole
Shubham_boroleAccepted solution
New Participant
Feb 4, 2020 3:53 PM UTC

As mentioned in first comment I was able to achieve this by adding disabled=true for selected item. Thanks again to @arunpatidar for the great article

5 replies

Shubham_borole
New Participant
Feb 10, 2020 3:43 PM UTC

Already added wha worked for me. This can be disregaded.

Translate
Shubham_borole
Shubham_boroleAuthorAccepted solution
New Participant
Feb 4, 2020 3:53 PM UTC

As mentioned in first comment I was able to achieve this by adding disabled=true for selected item. Thanks again to @arunpatidar for the great article

Translate
sunjot16
Employee
Feb 3, 2020 10:25 PM UTC

Once the select tag is created, you can read that document element using query selector, parse through its options and set the "selected" attribute to the second option.

 

Hope it helps !!

Translate
Shubham_borole
New Participant
Feb 4, 2020 3:52 PM UTC
yeah, I think I tried that, but when we choose to open the dialog and we are within "$(document).on("dialog-ready", function () " the "dialog box" is not available and hence we are unable to query the saved/selected item or root itself. is
Translate
Shubham_borole
New Participant
Feb 3, 2020 8:49 PM UTC
I added vm.put("selected", true); vm.put("disabled", true); , in that case it seems to work. I get the expected view, just that the selected item will be disabled. But if I keep just vm.put("selected", true); then the selected value is not "selected"
Translate