I have 3 checkbox widget in my dialog & and on the basis of no of selection code perform the logic, Issue is when i tick option1 option2, then they set their value in the content node to "ON". But if i edit the same component option1, option2 are select , i unselect the one and click ok, Still in the content node property exist with value "ON".
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
jcr:primaryType="cq:Dialog"
title="dialog"
xtype="dialog">
<items
jcr:primaryType="cq:Widget"
xtype="tabpanel">
<items jcr:primaryType="cq:WidgetCollection">
<tab1
jcr:primaryType="cq:Panel"
title="Select Options">
<items jcr:primaryType="cq:WidgetCollection">
<facebook
jcr:primaryType="cq:Widget"
fieldLabel="Facebook"
name="./facebook"
xtype="checkbox"/>
<twitter
jcr:primaryType="cq:Widget"
fieldLabel="Twitter"
name="./twitter"
xtype="checkbox"/>
<linkedin
jcr:primaryType="cq:Widget"
fieldLabel="Linkedin"
name="./linkedin"
xtype="checkbox"/>
</items>
</tab1>
</items>
</items>
</jcr:root>
I have not had a lot of success with the checkbox xtype. Rather, try the selection xtype, with a type of checkbox.
<facebook
jcr:primaryType="cq:Widget"
fieldLabel="Facebook"
name="./facebook"
type="checkbox"
xtype="selection"/>
the problem you have is that when you uncheck the checkbox, the form is simply not sending that field into the POST, so Sling simply does not modify that property at all.
To be able to persist the unchecked state you need to add default values. You can do that with Sling Suffixes.
parameter@Delete, causes a property to be deleted from jcr if no other value has been sent. in your case you could interpret no property as uncheckedparameter@DefaultValue can be used to send a default value in case parameter was sent without any valueparameter@UseDefaultWhenMissing = true, can be used to force Sling to use the default value when the parameter was not sent at all.So, in your particular case, add hidden fields (xtype:hidden) with the following names & values.
./facebook@DefaultValue="off"./facebook@UseDefaultWhenMissing="true"That would make sure that the value "off" is used when the checkbox is unchecked.
ps-Yes, it is that annoying to use checkboxes in AEM/CQ
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With