How to set default value in a Touch UI select element? | Community
Skip to main content
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by arunpatidar

Yes, it is possible, please check

https://github.com/arunpatidar02/aem63app-repo/blob/master/java/DemoDailogDropdown.java 

3 replies

Level 3
June 9, 2022

thanks @himanshu_jain 
I tried both sites but it's not setting default values

SantoshSai
Community Advisor
Community Advisor
June 9, 2022

Hi @naruk89179065 ,

I believe you are using 

sling:ResourceType: granite/ui/components/foundation/form/select

In that case, you can use cq:template node to set initial default values for any kind of select datasource, textfield, radiogroup, checkbox etc. resource type.

Just add cq:template node inside AEM component.

<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0"
    jcr:primaryType="nt:unstructured"
    <jcrPropertyName>="<default value here>"/>

Hope that helps you!

Regards,

Santosh

 

Santosh Sai
BrianKasingli
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
June 10, 2022

@naruk89179065,

It really depends on which granite UI field are you targeting. Typically you will add an extra property to the XML configuration.


But here's a quick run down for which property sets a default value for which Granite UI fields that you are targeting:

  1. checkbox - value, link reference 
  2. textarea - value, link reference
  3. pathfield - cannot set default, link reference
  4. select - selected, link reference
  5. radiogroup - checked, link reference
  6. numberfield - value, link reference
  7. fileupload - cannot set default, link reference
  8. colorpicker - value, link reference

Checkout the full guide, cheat sheet reference guide which include code examples and pre-configured touch UI - https://sourcedcode.com/blog/aem/aem-granite-ui-1-0-form-components-xml-cheat-sheet-reference-guide

Level 3
June 10, 2022

thanks @briankasingli 

Is it possible to add a default option for the data source in select?

 

arunpatidar
Community Advisor
arunpatidarCommunity AdvisorAccepted solution
Community Advisor
June 10, 2022