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

[Solved] Change onSelect handler after menu creation?

1 Answer 109 Views
Menu
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Sean
Top achievements
Rank 1
Sean asked on 01 Jun 2012, 12:53 AM
Hello,

Here's my scenario: I have several nested dialogs (contained in Telerik MVC Windows) that are loaded as partial views.  There is a dialog-specific object that encapsulates the functionality of each of these dialogs and contains a handler for the each dialog's menu.  I'd like to bind the onSelect handler of each dialog's menu to a method in the javascript dialog object.  From the script that is emitted when the menu loads, I see a call like this "jQuery('#createOrEdit_menu').tMenu({ onSelect: createOrEditMenuSelect });".  I've tried this code in the handler that initializes the dialog, but I'm not having any luck.

I built a simple test project that has a menu declared in a partial view like this:

Html.Telerik().Menu().Name("createOrEdit_menu")
    .ClientEvents(events => events.OnSelect("grokMe"))
    .Items(menu =>
<snip>


And then in the AJAX handler that loads the partial view:

success: function (r) {
    var dlg = $("#new_dlg").data('tWindow');
    dlg.center();
    dlg.title("New");
    dlg.open();
    dlg.content(r);
    jQuery('#createOrEdit_menu').tMenu({ onSelect: createOrEditMenuSelect });
}


And the sampler handler, declare in the calling view:

function createOrEditMenuSelect(e) {
    var item = $(e.item);
    if (item.text() === "Cancel") {
        $("#new_dlg").data("tWindow").close();
    }
}


Problem is, createOrEditMenuSelect in not called, rather the "grokMe" function that is contained in the partial view is called.  So, my question is...can I change the onSelect handler of the menu after it has been created?

Thanks for taking a look...

Sean

1 Answer, 1 is accepted

Sort by
0
Sean
Top achievements
Rank 1
answered on 01 Jun 2012, 05:56 PM
After doing some spelunking in the source, I found that this solution.

After the menu has fully loaded (I have this executing after a short interval), I use this code to set the onSelect handler.

jQuery('#createOrEdit_menu').unbind("select");
jQuery('#createOrEdit_menu').data("tMenu").onSelect = createOrEditMenuSelect;
jQuery('#createOrEdit_menu').bind("select", jQuery('#createOrEdit_menu').data("tMenu").onSelect);
Tags
Menu
Asked by
Sean
Top achievements
Rank 1
Answers by
Sean
Top achievements
Rank 1
Share this question
or