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

[Solved] enable/disable item based on value

1 Answer 73 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.
Eva
Top achievements
Rank 1
Eva asked on 11 Apr 2012, 03:49 PM
I have the following block of code to define two of my menu items:

items.Add()
    .Text("<#= IsLocked ? \"Unlock\" : \"Lock\" #>")
    .HtmlAttributes(new {@class = "grid-row-action-lock"})
    .ImageUrl("~/Content/Common/Images/Icons/<#= IsLocked ? \"unlocked\" : \"locked\" #>.png")
    .Action("_LockAjax", "Attribute", new {id = "<#= ID #>"});
items.Add()
    .Enabled("<#= InUse ? false : true #>")
    .Text("Recycle")
    .HtmlAttributes(new {@class = "grid-row-action-delete"})
    .ImageUrl("~/Content/Common/Images/Icons/recycle.png")
    .Action("_DeleteAjax", "Attribute", new {id = "<#= ID #>"});

The first one works perfectly.  The second gives me an error that a boolean is expected.  Is there a way to do what I am trying to do here?
Thanks!

1 Answer, 1 is accepted

Sort by
0
Eva
Top achievements
Rank 1
answered on 12 Apr 2012, 09:55 PM
I decided to run a client event on load and that is working to make the item appear disabled.  However, it is not truly disabled.  I see there is another thread on that (http://www.telerik.com/community/forums/aspnet-mvc/menu/how-to-trully-disable-menu-items.aspx), so I will not address the lack of really being disabled here.  Just in case someone comes across this though and wants to know the answer.

I implemented a client side event with this line added to my menu:
.ClientEvents(events => events.OnLoad("Menu_onLoad"))

Then this is the code for the Menu_onLoad function:
function Menu_onLoad(e) {
    var menu = jQuery(e.target).data('tMenu');
    var i = jQuery("li", menu.element)[3];
    if (i.innerHTML.contains('In Use'))
        menu.disable(i);
}

Tags
Menu
Asked by
Eva
Top achievements
Rank 1
Answers by
Eva
Top achievements
Rank 1
Share this question
or