javascript - Make Kendo UI DropDownList display the Title attribute of Select Control as a kendoTooltip - Stack Overflow

What do I need to do in order to make the Kendo UI DropDownList display the title attribute as a kendoT

What do I need to do in order to make the Kendo UI DropDownList display the title attribute as a kendoTooltip?

This is what I'm doing: /

<div class="editor-field">
    <select id="Title" name="Title" title="What's your title?">    
    <option value="Mr.">Mr.</option>
    <option value="Mrs.">Mrs.</option>
    <option value="Miss">Miss</option>
</select>
</div>


$(function () {  
var tooltip = $('#Title').kendoTooltip({
        position: "right",
        autoHide: true,
        width: 280,
        animation: {
            open: {
                effects: "slideIn:right",
                duration: 300
            },
            close: {
                effects: "slideIn:right",
                reverse: true,
                duration: 200
            }
        }
    });
$("#Title").kendoDropDownList();
});

What do I need to do in order to make the Kendo UI DropDownList display the title attribute as a kendoTooltip?

This is what I'm doing: http://jsfiddle/EdsonF/qDRv3/1/

<div class="editor-field">
    <select id="Title" name="Title" title="What's your title?">    
    <option value="Mr.">Mr.</option>
    <option value="Mrs.">Mrs.</option>
    <option value="Miss">Miss</option>
</select>
</div>


$(function () {  
var tooltip = $('#Title').kendoTooltip({
        position: "right",
        autoHide: true,
        width: 280,
        animation: {
            open: {
                effects: "slideIn:right",
                duration: 300
            },
            close: {
                effects: "slideIn:right",
                reverse: true,
                duration: 200
            }
        }
    });
$("#Title").kendoDropDownList();
});
Share Improve this question asked Nov 2, 2013 at 20:19 EdsonFEdsonF 2,8284 gold badges31 silver badges34 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

The problem is that title belong to the original select but not to Kendo UI decorated element. When you convert a select in a KendoUI DropDownList it creates some extra HTML elements around but title is not copied into this element.

So, what you can do is:

// Create DropDownList
var title = $("#Title").kendoDropDownList().data("kendoDropDownList");
// Copy title from the select into the `wrapper` element
title.wrapper.attr("title", $("#Title").attr("title"));
// Now, define the tooltip for this wrapper element
var tooltip = title.wrapper.kendoTooltip({
    position: "right",
    autoHide: true,
    width: 280,
    animation: {
        open: {
            effects: "slideIn:right",
            duration: 300
        },
        close: {
            effects: "slideIn:right",
            reverse: true,
            duration: 200
        }
    }
});

The JSFiddle here: http://jsfiddle/OnaBai/qDRv3/4/

As it was previously mentioned, your original tag gets wrapped by Kendo UI and 'title' attribute is not copied over. It is relatively easy to fix by extending the DropDownList Kendo.UI class. Here is how I fixed it in my project (TypeScript):

export class DropDownListX extends kendo.ui.DropDownList {

    // Constructor
    constructor(element: Element, options?: kendo.ui.DropDownListOptions) {
        super(element, options);

        // Copy title attribute from element node to its parent (wrapper created by kendo ui)
        $(element).parent().attr("title", $(element).attr("title"));
    }
}

// Create an alias of the prototype (required by kendo.ui.plugin)
DropDownListX.fn = DropDownListX.prototype;
// Deep clone the widget default options
DropDownListX.fn.options = $.extend(true, { }, kendo.ui.DropDownList.fn.options);
// Specify the name of your Kendo UI widget. Used to create the corresponding jQuery plugin.
DropDownListX.fn.options.name = "DropDownListX";
// Create a jQuery plugin.
kendo.ui.plugin(DropDownListX);

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744239620a4564641.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信