Stupid Question Time

4 posts, 0 answers
  1. DavidOBrien
    DavidOBrien avatar
    14 posts
    Member since:
    Sep 2012

    Posted 01 Apr 2013 Link to this post

    $menu = new \Kendo\UI\Menu('menu');
    $menu->addItem(
        new \Kendo\UI\MenuItem('Home')
        ,new \Kendo\UI\MenuItem('Blog')
        ,new \Kendo\UI\MenuItem('Documentation')
        ,new \Kendo\UI\MenuItem('Code Changes')
        ,new \Kendo\UI\MenuItem('Community')
        ,new \Kendo\UI\MenuItem('Pricing')
        ,new \Kendo\UI\MenuItem('Downloads')
        ,new \Kendo\UI\MenuItem('About Us')
    );
    How do I specify the url to open if that item is selected?
    It seems it should be easier than having to add a content("<a href="link.php">Home</a>") to each item shouldn't it?
  2. Alexander Valchev
    Admin
    Alexander Valchev avatar
    2875 posts

    Posted 03 Apr 2013 Link to this post

    Hi David,

    Generally speaking, you should be able to specify the url of the MenuItem through its url method.
    <?php
    $item = new \Kendo\UI\MenuItem();
    $item->text('Google');
    $item->url('http://www.google.com');
    ?>

    I am afraid that currently the method is not available - we will log this as a bug and will do our best to provide a fix as soon as possible. As a small sign of our appreciation for this discovery I updated your Telerik points.

    Meanwhile, as a workaround please set the link as content:
    <?php>
    $item = new \Kendo\UI\MenuItem('<a href="http://www.google.com">Google</a>');
    ?>


    Kind regards,
    Alexander Valchev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. UI for ASP.NET AJAX banner
  4. Oscar
    Oscar avatar
    6 posts
    Member since:
    Mar 2013

    Posted 18 Apr 2013 Link to this post

    This will show the html as literal text.

    What I've done as a workaround is change the renderContent function in UI/MenuItem.php. This way you will be able to use the url function on the item.
    protected function renderContent($element) {
        $content = $this->getProperty('content');
                $url = $this->getProperty('url');
     
        if ($content) {
            $subgroup = new \Kendo\Html\Element('ul');
            $subitem = new \Kendo\Html\Element('li');
            $anchor = new \Kendo\Html\Element('a');
                     
            if ($url) {
                            $anchor->attr('href', $url);
                            $anchor->html($content);
                            $subitem->append($anchor);
                        } else {
                            $subitem->html($content);
                        }
     
            $subgroup->append($subitem);
            $element->append($subgroup);
        }
    }
    Though I'm waiting for the feature to become available as well so the item is selected by default if the browsing URL matches the URL provided in the url function. Can't seem to find a simple workaround for that as this also needs an altering in the kendo javascript code.
  5. Alexander Valchev
    Admin
    Alexander Valchev avatar
    2875 posts

    Posted 22 Apr 2013 Link to this post

    Hello David,

    Thank you for the feedback.
    I am glad to inform you that this bug is fixed in the latest internal build. Please download it and give it a try. The syntax for creating the menu item is:
    $foo = new \Kendo\UI\MenuItem();
    $foo->text('foo');
    $foo->url('http://www.google.com');


    Kind regards,
    Alexander Valchev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top
UI for ASP.NET AJAX banner