I am trying to have a default checked checkbox on a component dialog when editing. Here are the properties on the field:
jcr:primaryType: widget
checked: tr
To set checkbox with a default value of checked and save the property as a Boolean property type in the JCR (rather than a String), use the following Classic UI settings:
<myCheckbox
jcr:primaryType="cq:Widget"
fieldLabel="My Checkbox"
name="./myCheckbox"
value="true"
defaultValue="true"
checkboxBoolTypeHint="{Boolean}true"
type="checkbox"
xtype="selection"/>
Or use the following settings in the Granite Touch UI:
<myCheckbox
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/foundation/form/checkbox"
text="My Checkbox"
name="./myCheckbox"
value="true"
checked="true"/>
<myCheckboxType
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/foundation/form/hidden"
name="./myCheckbox@TypeHint"
value="Boolean"/>
There's a detailed writeup and demo at http://www.nateyolles.com/blog/2015/11/aem-checkboxes-using-sling-post-servlet.
To have this saved as a Boolean...
<nodeName
jcr:primaryType="cq:Widget"
fieldLabel="check this nodename"
name="./nodeName"
defaultValue="{Boolean}false"
type="checkbox"
xtype="selection" />
<nodeNameHint
jcr:primaryType="cq:Widget"
ignoreData="{Boolean}true"
name="./nodeName@TypeHint"
value="Boolean"
xtype="hidden"/>
Yes, it looks like the documentation is a little wonky. I did some experimenting, and this combination of properties works for me:
defaultValue (String) true
fieldLabel (String) Foo Mode
inputValue (String) false
jcr:primaryType (Name) cq:Widget
name (String) ./foomode
type (String) checkbox
xtype (String) selection
The defaultValue property appears to be the key.
You do have cq:Widget for your primary type, not widget, do you not?