Thursday, June 7, 2012

How to create a OK CANCEL alert prompt in CQ

Problem: The problem was to change the simple alert into OK CANCEL Message Box in CQ ExtJS and to have different functionality on the basis of clicked button?

Solution:
Simple alert functionality is written as:
CQ.Ext.MessageBox.alert(
                                 CQ.I18n.getMessage("Title"),
                                 CQ.I18n.getMessage("Message"),
                                 function(){
                                          //User defined functionlity
                                 }
);

In order to turn it into OK CANCEL prompt use the below code
CQ.Ext.Msg.show( {
                          title : CQ.I18n.getMessage("Title"),
                          msg : CQ.I18n.getMessage("Message"),
                          buttons : CQ.Ext.Msg.OKCANCEL,
                          fn : function(buttons) {
                              if(buttons == "ok")
                                  //User defined functionlity
                              },
                            icon : CQ.Ext.MessageBox.QUESTION
                      });


For further reference you can check the below reference from Adobe Day CQ5 link:
http://dev.day.com/docs/en/cq/current/widgets-api/index.html
and Search using the key as  "MessageBox"

No comments:

Post a Comment