Welcome Guest Search | Active Topics | Sign In | Register

Javascript errors in menu Options
Laurynas
Posted: Wednesday, March 31, 2010 2:53:26 AM
Rank: Advanced Member
Groups: Member

Joined: 3/23/2010
Posts: 35
Hello,

We are trying out if your menu control fits our needs, and it looks pretty well except one javascript problem which I cannot solve and can't find how to work around it.

When the menu has at least one separator, the setDisabled function on menu items crash with this message:
Code:
'this.apu.tagName' is null or not an object


Everything starts working fine after removing the IsSeparator="true" attribute.

This is the page to reproduce this:
Code: HTML/ASPX
<%@ Page Language="C#" %>

<%@ Register Assembly="EO.Web" Namespace="EO.Web" TagPrefix="eo" %>

<script type="text/javascript">
    function setDisabledRecursive(menuGroup)
    {
        for (var i = 0; i < menuGroup.getItemCount(); ++i)
        {
            var menuItem = menuGroup.getItemByIndex(i);
            var subGroup = menuItem.getSubGroup();
            if (subGroup)
            {
                setDisabledRecursive(subGroup);
            }
            menuItem.setDisabled(!menuItem.getDisabled());
        }
    }

    function menu_loaded()
    {
        var menu = eo_GetObject("menu1");
        setDisabledRecursive(menu.getTopGroup());
    }
</script>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Menu test </title>
    <meta http-equiv="X-UA-Compatible" content="IE=8" />
</head>
<body>
    <form runat="server">
    <eo:Menu runat="server" ID="menu1" ClientSideOnLoad="menu_loaded">
        <TopGroup>
            <Items>
                <eo:MenuItem Text-Html="test">
                    <SubMenu>
                        <Items>
                            <eo:MenuItem Text-Html="test">
                            </eo:MenuItem>
                            <eo:MenuItem IsSeparator="true">
                            </eo:MenuItem>
                        </Items>
                    </SubMenu>
                </eo:MenuItem>
                <eo:MenuItem Text-Html="test">
                </eo:MenuItem>
            </Items>
        </TopGroup>
    </eo:Menu>
    </form>
</body>
</html>

eo_support
Posted: Wednesday, March 31, 2010 7:30:14 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

Please use the following code:

Code: JavaScript
//This function is called when a menu group is
//about to expand. info argument contains 
//information about which group is about to 
//expand. In addition, menu_loaded also calls
//this function without providing info parameter,
//in which case it means we need to disable the
//top group
function menugroup_expand(e, info)
{
    //Get the menu group to be disabled
    var group;
    if (info)
        group = info.getItem().getSubGroup();
    else
    {
        var menu = eo_GetObject("Menu1");
        group = menu.getTopGroup();
    }
    
    //Disable all items
    for (var i = 0; i < group.getItemCount(); ++i)
    {
        var menuItem = group.getItemByIndex(i);
        menuItem.setDisabled(!menuItem.getDisabled());
    }        
}

function menu_loaded()
{
    //Disable the top group
    menugroup_expand();
}


Code: HTML/ASPX
<eo:Menu ......
ClientSideOnLoad="menu_loaded" 
ClientSideOnGroupExpand="menugroup_expand">
    .....
</eo:Menu>


The key difference is the code to disable items are called when a menu group is about to expand, not when the menu is loaded. The menu does not create all the sub menus when it is loaded because user may never use some sub menus.

Thanks!
Laurynas
Posted: Wednesday, March 31, 2010 7:54:43 AM
Rank: Advanced Member
Groups: Member

Joined: 3/23/2010
Posts: 35
Thanks, that worked like a charm!
eo_support
Posted: Wednesday, March 31, 2010 7:59:51 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
You are welcome. Please feel free to let us know if you have any more questions.

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.