Hi Team
I have an issue when checkbox is unchecked the value is empty "" instead I would like to store it as false.
When it is checked I am getting as "true"
could you please advise me on the below 2 issues:
1. When checkbox is not checked or unchecked I want value as false
2. When checkbox is checked, i am getting "true" in json which is a string. Can I get as boolean like true.
below is my node structure :
<disable
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/checkbox"
fieldDescription="Checking will add a check icon"
name="./disable"
text="disable"
checked="{Boolean}false"
value="{Boolean}true"
deleteHint="{Boolean}false"/>
Views
Replies
Total Likes
Hi @Prashardan
Can you try with new page? it may not work with existing authored component.
Views
Replies
Total Likes
I am using this in the content fragment model. Checked value is coming as true which is fine but unCheckedValue is not coming as false
Views
Replies
Total Likes
You can use
Views
Replies
Total Likes
@DPrakashRaj I have tried the same way but it is not working. I am using this in the content fragment model. Checked value is coming as true which is fine but unCheckedValue is not coming as false
Views
Replies
Total Likes
Hi @Prashardan,
1. When checkbox is unchecked, store value as false
By default, unchecked checkboxes don't submit any value — which is why you’re seeing ""
(empty string) or nothing in the JCR node.
Try this:
<disable
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/checkbox"
fieldDescription="Checking will add a check icon"
name="./disable"
text="disable"
checked="{Boolean}false"
uncheckedValue="{Boolean}false"
value="{Boolean}true"
deleteHint="{Boolean}true"/>
uncheckedValue
: This ensures false
is stored when the checkbox is not checked.
deleteHint=true
: Ensures the field gets deleted or replaced with the uncheckedValue
during POST.
"true"
as string, want actual boolean true
When reading the value in your servlet/model or exporting it to JSON via Sling Model, sometimes "true"
appears as a string because of how it's stored or serialized.
Make sure you're using the correct data type in your Java model.
@ValueMapValue
@Optional
private boolean disable;
This will automatically treat "true"
or "false"
as a boolean, not a string.
If using Sling Model Exporter, ensure the value is exported as a boolean:
@Exporter(name = "jackson", extensions = "json")
public class MyModel implements MyModelInterface {
@ValueMapValue
private boolean disable;
@Override
public boolean isDisable() {
return disable;
}
}
This will ensure your final JSON has:
"disable": true
or
"disable": false
— as actual booleans, not strings.
Hope that helps!
Regards,
Santosh
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies