How to make checkbox default checked below code is not working | Community
Skip to main content
Level 6
Sep 14, 2021 9:23 AM UTC
Solved

How to make checkbox default checked below code is not working

<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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Rohit-Negi
Rohit-NegiAccepted solution
Level 3
Sep 14, 2021 11:36 AM UTC

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.

7 replies

Anny0505
New Participant
Sep 14, 2021 5:36 PM UTC

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

Translate
Shubham_borole
New Participant
Sep 14, 2021 4:57 PM UTC

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"/>
Translate
Rohit-Negi
Rohit-NegiAccepted solution
Level 3
Sep 14, 2021 11:36 AM UTC

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.

Translate
Dipti_Chauhan
New Participant
Sep 14, 2021 10:43 AM UTC

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

Translate
Asutosh_Jena_
New Participant
Sep 14, 2021 10:03 AM UTC

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"/>
Translate
Ronnie09Author
Level 6
Sep 14, 2021 10:09 AM UTC

@asutosh_jena_ 

Checkbox is checked but value it is returning is false

Translate
Asutosh_Jena_
New Participant
Sep 14, 2021 10:12 AM UTC

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/ui/components/coral/foundation/form/checkbox/index.html

 

Thanks

Translate