Expand my Community achievements bar.

SOLVED

How to set default value in a Touch UI select element?

Avatar

Level 3

How to set default value in a Touch UI select element in AEM 6.5

 

@arunpatidar  @DEBAL_DAS 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor
6 Replies

Avatar

Community Advisor

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>"/>

Screen Shot 2022-06-09 at 1.49.40 PM.png

Hope that helps you!

Regards,

Santosh

 

Avatar

Community Advisor

@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

Avatar

Level 3

thanks @BrianKasingli 

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

naruk89179065_0-1654834946006.png

 

Avatar

Correct answer by
Community Advisor