Skip to content

Instantly share code, notes, and snippets.

@nateyolles
Last active April 12, 2023 03:00
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save nateyolles/e5eed811dc9c35961c23 to your computer and use it in GitHub Desktop.
Save nateyolles/e5eed811dc9c35961c23 to your computer and use it in GitHub Desktop.
AEM Touch UI component dialog checkboxes
<!-- Checked checkbox will result in a String property of "true" -->
<myCheckbox
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/foundation/form/checkbox"
text="My Checkbox"
name="./myCheckbox"
value="true"/>
<!-- Checked checkbox will result in a Boolean property of true-->
<myBooleanCheckbox
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/foundation/form/checkbox"
text="My Boolean Checkbox"
name="./myBooleanCheckbox"
value="true"/>
<myBooleanCheckboxType
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/foundation/form/hidden"
name="./myBooleanCheckbox@TypeHint"
value="Boolean"/>
<!-- Checkbox defaults to checked and saves a Boolean value of true -->
<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"/>
@leojplin
Copy link

leojplin commented Nov 3, 2016

It doesn't work in a custom multifield..Why doesn't Adobe provide an official multifield widget that we can put anything in? It seems essential to my everyday work. The OOTB one only works with one field, which is pretty useless and all the custom one on the internet will break for one or the other component that we need. I don't want to create my own custom one especially since the Granite API is not documented well, if at all.

@cmrockwell
Copy link

Thanks for this reference! I've found it useful.

I wouldn't recommend the last example tho. While it does default to true (checked). If the user un-checks the box, submits and opens the dialog again, then it will show the field as checked even though the saved value is false (or missing)

@dbunk
Copy link

dbunk commented Feb 10, 2020

The uncheckedValue is working for me on AEM 6.5 inside of a granite/ui/components/coral/foundation/form/multifield. I'm using it to check whether to open a link in a new tab or not. This is what my dialog looks like for the field:

<newTab
	jcr:primaryType="nt:unstructured"
	sling:resourceType="granite/ui/components/coral/foundation/form/checkbox"
	text="Open link in new tab"
	name="./newTab"
	uncheckedValue="_self"
	value="_blank"
	checked="true"/>

Just be sure that uncheckedValue does not equal empty string as it won't be stored as a property (the property will just disappear from the node). AEM will check the checkbox if the property doesn't exist. For me this is what was causing the checkboxes to recheck themselves when I subsequently opened the dialog. Setting uncheckedValue with a value other than "" fixed the issue.

@knoxrover
Copy link

The uncheckedValue is working for me on AEM 6.5 inside of a granite/ui/components/coral/foundation/form/multifield. I'm using it to check whether to open a link in a new tab or not. This is what my dialog looks like for the field:

<newTab
	jcr:primaryType="nt:unstructured"
	sling:resourceType="granite/ui/components/coral/foundation/form/checkbox"
	text="Open link in new tab"
	name="./newTab"
	uncheckedValue="_self"
	value="_blank"
	checked="true"/>

Just be sure that uncheckedValue does not equal empty string as it won't be stored as a property (the property will just disappear from the node). AEM will check the checkbox if the property doesn't exist. For me this is what was causing the checkboxes to recheck themselves when I subsequently opened the dialog. Setting uncheckedValue with a value other than "" fixed the issue.

hey there
I am a beginner with AEM 6.5 and I want to implement something as below. Can u help me witht his?

Create dialog box for custom link component s, asking authors to choose if they would like the link to be opened in new tab/windows using checkbox and label

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment