This is a migrated thread and some comments may be shown as answers.

blockConfirm on RadMenuItemClicking event

4 Answers 106 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Dan Miller
Top achievements
Rank 1
Dan Miller asked on 26 Jul 2010, 11:10 PM
I am using a context menu and when a user clicks on a certain menuitem I want a confirm dialog to appear asking whether or not it should proceed with the onclick event. If the user wants to proceed, then the onclick event is triggered, if the user does not, then nothing happens and the confirm dialog just closes. I have tried this using the blockConfirm as shown:
window.blockConfirm = function (text, mozEvent, oWidth, oHeight, callerObj, oTitle)
{
  var ev = mozEvent ? mozEvent : window.event; //Moz support requires passing the event argument manually
  //Cancel the event
  ev.cancelBubble = true;
  ev.returnValue = false;
  if (ev.stopPropagation) ev.stopPropagation();
  if (ev.preventDefault) ev.preventDefault();
 
  //Determine who is the caller
  var callerObj = ev.srcElement ? ev.srcElement : ev.target;
 
  //Call the original radconfirm and pass it all necessary parameters
  if (callerObj)
  {
    //Show the confirm, then when it is closing, if returned value was true, automatically call the caller's click method again.
    var callBackFn = function (arg)
    {
      if (arg)
      {
        callerObj["onclick"] = "";
        if (callerObj.click) callerObj.click(); //Works fine every time in IE, but does not work for links in Moz
        else if (callerObj.tagName == "A") //We assume it is a link button!
        {
          try
          {
            eval(callerObj.href)
          }
          catch (e)
          {
          }
        }
      }
    }
    radconfirm(text, callBackFn, oWidth, oHeight, callerObj, oTitle);
  }
  return false;
}
function RadContextMenu_ItemClicking(sender, eventArgs)
{
  var item = eventArgs.get_item();
    if (item.get_text().substring(0, 7).toLowerCase() == "publish")
    {
        //display radconfirm popup
        return blockConfirm('message', eventArgs, 340, 100, '', 'Confirm Publish');
    }
  if (item.get_text().substring(0, 7).toLowerCase() == "version" || item.get_text().substring(0, 7).toLowerCase() == "publish")
  
    eventArgs.set_cancel(true);
  }
  else
  {
    //disable all context menus
    <asp:Literal ID="LiteralDisableContextMenu" runat="server" />
  }
}

I am pretty sure the problem is with the eventArgs variable that I am sending the blockConfirm. I have the blockConfirm working on a different part of my project when triggered from an ImageButton and that call is:

return blockConfirm('Are you sure you want to delete this item?', event, 340, 100, '', 'Confirm Delete?');

When I try using the variable "event" with the onclientclicking I get an error saying it does not exist. So what do I need to do to make this work with a RadMenuItem?

I read on the forums and could not find any answer, however this has been asked before here: http://www.telerik.com/community/forums/aspnet-ajax/treeview/radconfirm-on-radtreeview-nodeclick.aspx







4 Answers, 1 is accepted

Sort by
0
Dan Miller
Top achievements
Rank 1
answered on 29 Jul 2010, 06:48 PM
No-one has a solution for this?
0
Accepted
Veronica
Telerik team
answered on 30 Jul 2010, 08:51 AM
Hello Dan Miller,

Please accept my appologies for the late answer.

You'll have to use the eventArgs.get_domEvent() instead of eventArgs to be able to work with the event.

Hope this helps.

All the best,
Veronica Milcheva
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Dan Miller
Top achievements
Rank 1
answered on 05 Aug 2010, 07:20 PM
Thanks that did the trick! However now I have a new problem. The blockConfirm is not stopping the ajax refresh that occurs when I click on a menu item. It shows up but does the ajax refresh regardless of whether I click "confirm" or "cancel".
function RadContextMenu_ItemClicking(sender, eventArgs)
{
  var item = eventArgs.get_item();
  var
mySplit = item.get_value().split(',');
  var publishDate = new Date(mySplit[1]);
  var now = new Date();
  //display radconfirm popup
  if(publishDate > now)
  return blockConfirm('Are you sure you want to publish \"<strong>' + mySplit[0] + '</strong>\"? This          content is currently set to be active ' + mySplit[1] + '.', eventArgs.get_domEvent(), 340, 100, '',        'Confirm Publish');
}
This is the ItemClicking event of the contextmenu. If you need any other code snippets please let me know.
0
Accepted
Cori
Top achievements
Rank 2
answered on 06 Aug 2010, 09:24 PM
Hello Dan,

You're return line should be replaced with a call to eventArgs.set_cancel(blockConfirm()), in order to stop the click event from happening.

I hope that helps.
Tags
Menu
Asked by
Dan Miller
Top achievements
Rank 1
Answers by
Dan Miller
Top achievements
Rank 1
Veronica
Telerik team
Cori
Top achievements
Rank 2
Share this question
or