Recently, a client requested I add a checkbox in AEM Asset’s image metadata schema. Surprisingly, checkboxes are not a field type in the OOTB metadata schema editor field options.
After further investigation, I found that AEM list of OOTB form fields for metadata schemas includes a checkbox, but we cannot use the field as it is commented out.
Enabling the Checkbox Field
Here’s how you can add a checkbox in the metadata schema editor:
/libs/dam/gui/coral/components/admin/schemaforms/formbuilder/v2/builditems.jspinto /apps folder
- Uncomment the code in builditems.jsp lines 93 to 101
<% Resource checkboxResource = formResourceManager.getCheckboxFieldResource(resource); %> <li class="field" data-fieldtype="checkbox"> <div class="formbuilder-template-title"><coral-icon icon="select" size="M"></coral-icon><span><%= i18n.get("Checkbox") %></span></div> <script class="field-properties" type="text/x-handlebars-template"> <sling:include resource="<%= checkboxResource %>" resourceType="dam/gui/coral/components/admin/schemaforms/formbuilder/formfields/v2/checkboxfield" /> </script> </li>
- When you refresh the schema editor you should now see the checkbox.
- Now you can drag and drop the checkbox into your schema. Save the schema and apply this schema to any folder under the DAM.
After that, if you go and edit metadata of any image in that folder, you can see the checkbox. If you check the checkbox, it will store true value into JCR with the associated property name.
A Catch: Checkbox State Not Reloading
However, if you reopen that image for editing metadata, you can see the checkbox is unchecked. This is happening because the script for the checkbox has a bug in how it determines if the checkbox is checked.
To make it work:
- In form.js replace the following in line #514
- Test it again. Now you can see the checkbox is selected.
Hopefully, this was helpful for you. To download the full package, click here.
Sagar is Adobe Certified Expert – Adobe Experience Manager Developer.