Determine the type of Keno Control from Javascript

0 Answers 51 Views
ComboBox
Sean
Top achievements
Rank 1
Iron
Iron
Sean asked on 12 May 2024, 11:29 PM

Is there a way to determine what kind of kind of control you have using JavaScript.  For example , if you have a form with several different kendo controls

.data("kendoNumericTextBox")

.data("kendoComboBox")

.data("kendoButton")

I only have the name and id of the control. Is there a way to determine what kind of kendo control that is represented.

I have tried looking through the  jquery selection but I do not see any thing that indicates whether the selection is a kendoNumericTextBox, kendoComboBox etc...

Anton Mironov
Telerik team
commented on 15 May 2024, 10:33 AM

Hi Sean,

In order to achieve the desired behavior, I would recommend trying a custom implementation as the following:

function getKendoWidgetType(element) {
    var kendoWidgets = [
        'kendoNumericTextBox',
        'kendoComboBox',
        'kendoButton',
        // Add other Kendo widgets you want to check for
    ];

    for (var i = 0; i < kendoWidgets.length; i++) {
        var widgetName = kendoWidgets[i];
        if ($(element).data(widgetName)) {
            return widgetName;
        }
    }

    return null;
}

var element = $('#myControlId'); // Replace with your control's id or selector
var widgetType = getKendoWidgetType(element);
if (widgetType) {
    console.log('The control is a: ' + widgetType);
} else {
    console.log('No Kendo widget found on the element.');
}

I hope this example helps.

Kind Regards,
Anton Mironov

 

No answers yet. Maybe you can help?

Tags
ComboBox
Asked by
Sean
Top achievements
Rank 1
Iron
Iron
Share this question
or