AEM 61 - Touch UI Fill Dialog Fields with Default Values on Image Drop


Fill Touch UI Dialog Fields with default values, on image upload or drag and drop from Asset Finder. Title textfield (granite/ui/components/foundation/form/textfield) is filled with the name of image dropped and Creator textarea (granite/ui/components/foundation/form/textarea) with metadata /jcr:content/metadata/xmp:CreatorTool

Demo | Package Install


1) Login to CRXDE Lite, create folder (nt:folder) /apps/touchui-dialog-field-fill-default

2) Create clientlib (type cq:ClientLibraryFolder/apps/touchui-dialog-field-fill-default/clientlib and set a property categories of String type to cq.authoring.dialogdependencies of type String[] with value underscore

3) Create file ( type nt:file ) /apps/touchui-dialog-field-fill-default/clientlib/js.txt, add the following


4) Create file ( type nt:file ) /apps/touchui-dialog-field-fill-default/clientlib/default.js, add the following code

(function ($, $document) {
    var DIALOG_SELECTOR = ".cq-dialog",
        FILE_UPLOAD_SELECTOR = ".cq-dialog .coral-FileUpload",
        TITLE_NAME = "[name='./title']", // dialog field for file name autofill
        CREATOR_NAME = "[name='./creator']"; // dialog field for creator auto fill - image-path/jcr:content/metadata/xmp:CreatorTool

    $document.on("dialog-ready", function () {
        var $element = $document.find(FILE_UPLOAD_SELECTOR),
            widget = $element ? $"fileUpload") : undefined;

        if (_.isEmpty(widget)) {


    function registerImageDrop(widget){
        //when the image is drag n dropped from asset finder
        widget.$element.on("assetselected", handleImageDrop);

        //when the image is uploaded from local file system
        widget.$element.on("fileuploadsuccess", handleFileUpload);

        var $dialog = $document.find(DIALOG_SELECTOR);

        function handleFileUpload(event){

        function handleImageDrop(event){
            var assetPath = event.path;


            $.ajax(assetPath + ".3.json").done(function(data){

    function getStringAfterLastSlash(str){
        if(!str || (str.indexOf("/") == -1)){
            return "";

        return str.substr(str.lastIndexOf("/") + 1);
})(jQuery, jQuery(document));


  1. Thanks for the article! One question, where can I find all the events available for listening? (like assetselected and fileuploadsuccess)

    1. Not fully documented yet i guess, but you can find some of them here...

      the "fileuploadsuccess" is triggered from coral api - http://localhost:4502/crx/de/index.jsp#/etc/clientlibs/granite/coralui2/js/coral.js

  2. Hi Sreekanth,
    Is there any way to drag and drop 2 ,3 images in a touch ui dialog and need resource for touch ui image multifield also.

    1. satya, some additional code should be added to image multifield to get it working

    2. I hope those changes are in js right?Can you share me that code.I need help for image drag and drop also not multifiled (ex : drag and drop 2 images only) in touch ui.

  3. Hi Sreekanth,

    I have been having issues binding evnts to "dialog-ready" because if your on a mobile breakpoint and open a dialog it loads in a new page, not in a true dialog, and this event never fires. Have you seen this or know an event to bind to whenever a dialog opens, not just in 'modal' form.

  4. On Image upload i want width and height of image to be prefilled as default value.How do i do it?

  5. Hi Sreekanth,
    On drag and drop of an image into the component, I need to auto-populate the "Title" and "Copyright Owner" values from DAM into my component (i will have two different text fields in my component). I'm using AEM 6.1 and Classic UI.

    How this can be achieved ?