Skip to main content

Adobe

Enabling Checkboxes in AEM Assets Metadata Schema

Checkbox Hero

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:

  1. Overlay /libs/dam/gui/coral/components/admin/schemaforms/formbuilder/v2/builditems.jsp into /apps folderbuilditems
  2. Uncomment the code in builditems.jsp lines 93 to 101
    checkbox-resource-metadata

    <% 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>
    
  3. When you refresh the schema editor you should now see the checkbox.checkbox
  4. 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:

  1. Overlay /libs/dam/gui/coral/components/admin/metadataeditor/clientlibs/metadataeditor/js/form.js
  2. In form.js replace the following in line #514 if($checkbox.is(":checked")){ with if(checkbox.hasAttribute("checked")){ form-js
  3. Test it again. Now you can see the checkbox is selected.

Hopefully, this was helpful for you. To download the full package, click here.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Sagar Hepat, Senior Technical Consultant

Sagar is Adobe Certified Expert - Adobe Experience Manager Developer.

More from this Author

Categories
Follow Us