How to make checkbox default checked below code is not working | Community
Skip to main content
New Participant
September 14, 2021
Solved

How to make checkbox default checked below code is not working

  • September 14, 2021
  • 5 replies
  • 3589 views

<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.
Best answer by Rohit-Negi

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.

5 replies

Anny0505
New Participant
September 14, 2021

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

Shubham_borole
New Participant
September 14, 2021

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"/>
Rohit-Negi
Rohit-NegiAccepted solution
New Participant
September 14, 2021

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.

Dipti_Chauhan
New Participant
September 14, 2021

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

Asutosh_Jena_
New Participant
September 14, 2021

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"/>
Ronnie09Author
New Participant
September 14, 2021

@asutosh_jena_ 

Checkbox is checked but value it is returning is false

Asutosh_Jena_
New Participant
September 14, 2021

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