Adding tooltip to ListBox options

1 Answer 10 Views
ListBox
Joshua
Top achievements
Rank 1
Iron
Joshua asked on 23 Apr 2024, 09:06 PM | edited on 23 Apr 2024, 09:10 PM

Just as the title states I'd like to add a tooltip or even title to the options in the listbox. So that when a uses hovers the option the tip appears. The first Listbox binding is done on a SelectListItem List.

 


                @(Html.Kendo().ListBox()
                .Name("lbOptions")
                .ConnectWith("lbSelectedOptions")
                .Selectable(ListBoxSelectable.Multiple)
                .Toolbar(toolbar =>
                {
                    toolbar.Position(Kendo.Mvc.UI.Fluent.ListBoxToolbarPosition.Right);
                    toolbar.Tools(tools => tools
                        .TransferTo()
                        .TransferFrom()
                        .TransferAllTo()
                        .TransferAllFrom()
                    );
                })
                .BindTo(ViewBag.Lists)
            )<!--End of lbProjects listbox-->
                @(Html.Kendo().ListBox()
                .Name("lbSelectedOptions")
                .BindTo(new List<SelectListItem>())
                .ConnectWith("lbOptions")
                .Selectable(ListBoxSelectable.Multiple)
            )<!--End of lbSelectedProjects listbox-->

1 Answer, 1 is accepted

Sort by
0
Anton Mironov
Telerik team
answered on 26 Apr 2024, 12:25 PM

Hi Joshua,

Thank you for the code snippet and the details provided.

In order to achieve the desired behavior, I would recommend using the following approach:

            $(document).ready(function () {
                $("#lbOptions").kendoListBox();

                var listBox = $("#lbOptions").data("kendoListBox");
                listBox.items().each(function() {
                    var itemText = $(this).text();
                  
                    if (!$(this).attr('title')) { 
                        $(this).attr('title', 'Tooltip for ' + itemText);
                    }
                });
            });
In the code above, I am using the "document.ready" scope which iterates all items in the ListBox and adds a tooltip for them.

Here is a dojo example that I prepared for the case:

I hope this achieves the desired result.

Kind Regards,
Anton Mironov
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages. If you're new to the Telerik family, be sure to check out our getting started resources, as well as the only REPL playground for creating, saving, running, and sharing server-side code.
Tags
ListBox
Asked by
Joshua
Top achievements
Rank 1
Iron
Answers by
Anton Mironov
Telerik team
Share this question
or