AEM: Create custom Touch Dialog UI edit client libraries

Hello, Let us see how to create a client library for Touch UI Dialog listeners.

It is always recommended to use custom clientlib category instead of using OOTB  categories.

Why we need to create a custom clientlib?

If we use the OOTB categories there are chances of embedding our listener code in to the framework JavaScript and it will be included in all pages all the time.

If there is any Error in our code, it will break the entire framework and EDIT mode will be hanged sometimes.

So it is always better to create our custom client library and include it in our dialog. This way it will be loaded on the page only when we open the dialog at least once.

Creating Client Library

We can create a Client Library Folder in any location under apps or etc/designs. But I personally prefer creating Client Libraries which are specific to Edit mode/Dialog under component node itself.

Let's create Client Library. 

  1. Create a folder clientlibs(sling:Folder) under component node (parellel to cq:dialog)
  2. Create a folder editor(cq:clientLibraryFolder) under clientlibs and added property categories String[] <category_name> (Must be same as value configured in dialog node)
  3. Create a folder js(nt:folder) and create a file listener.js inside it
  4. Create a file js.txt parallel to js folder and add #base=js listener.js (in two different lines)
  5. Save changes
client-lib

                                                                      js.txt file


Now we are done with creating the cilentlib. Let us configure it in our dialog.

There are two ways to load clientlib from dialog.

  1. Set a property extraClientlibs to cq:dialog node and add category as value
  2. Create node(nt:unstructured) and use granite/ui/components/coral/foundation/includeclientlibs

1.Using extraClientlibs

Add a property extraClientlibs (String[]) to cq:dialog node and add custom clientlib category.


2. Using granite/ui/components/coral/foundation/includeclientlibs

  • Create a node with name clientlibs under tab/items
  • Add property sling:resourceType (String) with value granite/ui/components/coral/foundation/includeclientlibs
  • Add property js (String) with custom clientlib category as value

Note: granite/ui/components/coral/foundation/includeclientlibs supports three properties js/css/categories. Here I am using only js.




Now we created our own custom clientlib and configured it in dialog. 

Open the listener.js file and start writing custom listener code with out using OOTB categories. 🙌

See how to Hide/Show Touch UI dialog fields based on checkbox selection

See how to AEM: Hide/Show Touch UI dialog fields based on radio selection

Hope you liked the post and it helped. Meet you in next post. Thank you very much for your time.

-AG


No comments:

Post a Comment