Expand my Community achievements bar.

SOLVED

How to make checkbox default checked below code is not working

Avatar

Level 7

<tab_on_off
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/checkbox"
defaultChecked="{Boolean}true"

checked="{Boolean}true"
name="./onoff"
text="Enable to turn On Data"
uncheckedValue="false"
value="true"/>

How to make checkbox default checked this is not working

1 Accepted Solution

Avatar

Correct answer by
Level 4

Hi @Ronnie09 

 

Can you Try the below:-

 

<tab_on_off

                        jcr:primaryType="nt:unstructured"

                        sling:resourceType="granite/ui/components/coral/foundation/form/checkbox"

                        fieldLabel="Page value"

                        name="./onoff"/>

<tab_on_off-default

                        jcr:primaryType="nt:unstructured"

                        sling:resourceType="/libs/granite/ui/components/coral/foundation/form/hidden"

                        name="./onoff@DefaultValue"

                        value="{Boolean}true"/>

 

Make sure name property(./onoff) remain the same with @DefaultValue appended in the hidden one.

View solution in original post

7 Replies

Avatar

Community Advisor

Hi @Ronnie09 

 

Please use the below code:

 

<tab_on_off
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/checkbox"
checked="{Boolean}true"
name="./onoff"
text="Enable to turn On Data"
value="true"/>

Avatar

Community Advisor

I see using the above code it works and returns the value as true.

 

Please use the above code only. After adding the code, when you open the dialog, you can see the checkbox value as selected. Now once you save the dialog, you can see the value as true. Until you save the dialog it will not return the value as true.

 

Please see the link here with official documentation:

https://www.adobe.io/experience-manager/reference-materials/6-5/granite-ui/api/jcr_root/libs/granite...

 

Thanks

Avatar

Community Advisor

Hi @Ronnie09 

  This should work

 

<tab_on_off
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/checkbox"
name="./onoff"
text="Enable to turn On Data"
value="true"/>

Avatar

Correct answer by
Level 4

Hi @Ronnie09 

 

Can you Try the below:-

 

<tab_on_off

                        jcr:primaryType="nt:unstructured"

                        sling:resourceType="granite/ui/components/coral/foundation/form/checkbox"

                        fieldLabel="Page value"

                        name="./onoff"/>

<tab_on_off-default

                        jcr:primaryType="nt:unstructured"

                        sling:resourceType="/libs/granite/ui/components/coral/foundation/form/hidden"

                        name="./onoff@DefaultValue"

                        value="{Boolean}true"/>

 

Make sure name property(./onoff) remain the same with @DefaultValue appended in the hidden one.

Avatar

Community Advisor

Hi @Ronnie09 

 

Can you please try and update value="{Boolean}true" as well instead of value="true". Do it for uncheckedValue as well or remove it and try.

 

<tab_on_off
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/checkbox"
checked="{Boolean}true"
name="./onoff"
text="Enable to turn On Data"
value="{Boolean}true"/>

Avatar

Community Advisor

@Ronnie09 ,

 

Please try below and see how it works.

<message
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/checkbox"
checked="{Boolean}false"
name="./message"
text="Is Active"
uncheckedValue="{Boolean}false"
value="{Boolean}true"/>