In AEM how to add a new node called “listeners” in the component dialog ,without using dialog.xml file. | Community
Skip to main content
Level 2
Aug 29, 2017 8:42 AM UTC
Solved

In AEM how to add a new node called “listeners” in the component dialog ,without using dialog.xml file.

Actaully i am using  "before submit" listener to do some validation for my selection box

I have reffered the following link:

https://helpx.adobe.com/experience-manager/using/classic_dialog_validation.html .

But "before submit" method calling only when i place  ,

dialog listener in the dialog root level only.

how to place  dialog listener in dialog root level(I checked in my project there is no dialog.xml file ,they using only java code  to construct  component dialog).

Can anyone please help me in  this ?

Dialog construction code :

@DialogField(name = DialogConstants.FIELD_NAME_PREFIX + PROPERTY_GNF_PROGRAM, fieldLabel = "GNF Program",

      fieldDescription = "(synchronized)",

    additionalProperties = {

          @Property(renderIn = Property.RenderValue.TOUCH,

                name = DialogConstants.PROPERTY_VALIDATION,

                value = "mt-gnf-program")

                     },

    listeners = {

    @Listener(name ="beforesubmit",

                     value = "function(dialog){" +

                     "  return gnfProgramValidation.beforeSubmit(dialog);" +

                             "}")

   })

           @Selection(

                    type = DialogConstants.TYPE_SELECT,

                    optionsProvider = "function(path, record) {" + "  return CQ.HTTP.eval('/content/global.gnfprograms.json');" + "}",

                    dataSource = GnfProgramsDataSource.RESOURCE_TYPE)

           public final String gnfProgram;

Java script code :

window.onload = function() {

gnfProgramValidation.init();

};

var  gnfProgramValidation = gnfProgramValidation || (function($) {

    function initialize() {

    };

    function validate() {

    alert("inside validate method");

        var res = true;

        return res;

    };

    return {

        beforeSubmit: validate,      

        init: initialize

    }

})(jQuery);

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
dhanubrpAccepted solution
Level 2
Sep 5, 2017 10:22 AM UTC

Thank you all for your support. Found the following way to solve the issue .

I added ValidateFields method from within the  2 listeners (FIELD_LISTENER_LOAD_CONTENT and FIELD_LISTENER_SELECTION_CHANGED)

function ValidateFields(dialog) {

dialog.on("beforesubmit", function(e) {

   if(<condtion failed>)

    CQ.Ext.Msg.alert(CQ.I18n.getMessage("Error"), CQ.I18n.getMessage("<error message>"));

    return false;

   } else {

    return true;

   }

}, this);

}

8 replies

dhanubrpAuthorAccepted solution
Level 2
Sep 5, 2017 10:22 AM UTC

Thank you all for your support. Found the following way to solve the issue .

I added ValidateFields method from within the  2 listeners (FIELD_LISTENER_LOAD_CONTENT and FIELD_LISTENER_SELECTION_CHANGED)

function ValidateFields(dialog) {

dialog.on("beforesubmit", function(e) {

   if(<condtion failed>)

    CQ.Ext.Msg.alert(CQ.I18n.getMessage("Error"), CQ.I18n.getMessage("<error message>"));

    return false;

   } else {

    return true;

   }

}, this);

}

Translate
smacdonald2008
Level 10
Aug 30, 2017 1:01 PM UTC

You can always build a package too for that part of your project - contains only those nodes. When you override the project, by rebuilding via Maven, you can reinstall the package.

Translate
viveksachdeva
New Participant
Aug 30, 2017 7:42 AM UTC

I believe you are using maven component plugin.. Component (CQ Component Plugin 4.1.0 API)  has reference of the properties that you can use with it. In case it doesnt work as expected, I believe creating an issue in github repo for that would be better as it is an external plugin..

Translate
dhanubrpAuthor
Level 2
Aug 30, 2017 7:38 AM UTC

Thanks for you suggestion Ratna Kumar,    

Yes we can add nodes by using CRXDE Lite . But once I build my project , then content modified through CRX will be erased.

Translate
dhanubrpAuthor
Level 2
Aug 30, 2017 7:37 AM UTC

Thanks for you suggestion Scott ,    

Yes we can add nodes by using CRXDE Lite . But once I build my project , then content modified through CRX will be erased.

Translate
Ratna_Kumar
Level 10
Aug 29, 2017 2:47 PM UTC

Hi,

You can use CRXDE Lite to add the nodes under the dialog and you can view the listeners dialogsubmit javascript code in dialog.xml.

But yes adding the listener's in the dilaog is the best practice.

Thanks,

Ratna.

Translate
smacdonald2008
Level 10
Aug 29, 2017 2:21 PM UTC

"how to place  dialog listener in dialog root level"

You use CRXDE Lite to add nodes to the dialog JCR nodes.

Translate
Ten_A
New Participant
Aug 29, 2017 8:49 AM UTC

Moved from Adobe Creative Cloud to Adobe Experience Manager.

Translate