SOLVED

How to make checkbox default checked below code is not working

Ronnie09
Level 3
Level 3

<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
Rohit_Negi550
Correct answer by
Level 3
Level 3

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
asutosh_jena
Community Advisor
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"/>
asutosh_jena
Community Advisor
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

Dipti_Chauhan
Community Advisor
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"/>

Rohit_Negi550
Correct answer by
Level 3
Level 3

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

snbaem
Community Advisor
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"/>
ArunaSurukunta
Level 4
Level 4

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