This is a migrated thread and some comments may be shown as answers.

Trying to develop an unobtrusive layer on Kendo

2 Answers 74 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Jerrie Pelser
Top achievements
Rank 1
Jerrie Pelser asked on 04 Jan 2012, 10:01 AM
Hi,

I have been playing around with Kendo to see whether we can use it in one of our projects.  One of the things I am trying to achieve is to develop and unobtrusive interface on top of Kendo.  The way I am going about this is as follows:

1. I mark the controls which I want to apply the Kendo UI to with a specific attributes, e.g. a textbox which should become a date picket I will mark with add a "data-ui-datepicker" attribute to.
2. I will then run javascripy once the page has loaded to call the appropriate Kendo methods for them, e.g. I will get all textboxes with the "data-ui-datepicker" attribute and call the kendoDataPicker() method on them.

This works fine but I also have sections of the page which is dynamically loaded.  Once it is loaded I will again call the method to apply to Kendo UI to the controls.  The problem is that the controls which already has the Kendo UI applied to then gets screwed up because it basically tries to apply the Kendo UI to the control a second time.

My question is whether you guys have any idea as to how I can work around this?  Is there any way to determine whether a control already has the Kendo UI applied so that I then don't call the kendo...() method a second time?

Also, do you have any plans to supply some sort of unobtrusive framework on top of Kendo?

Hope this makes sense.

Thanks!

2 Answers, 1 is accepted

Sort by
0
Vesselin Obreshkov
Top achievements
Rank 2
answered on 05 Jan 2012, 03:55 AM
Make sure before you create a control that $('#control_id').data('kendoDropDownList') doesn't exist for a drop down list for instance.

Don't have VS on this computer but something like this might work?

$('[selector-for-your-dropdowns]').each(function () {
  if ($(this).data('kendoDropDownList') == undefined) {
    $(
this).kendoDropDownList();
  }
});

Not sure if the data('...') == undefined will work but this is the general idea - check if the control has data('kendoControlName') set before trying to re-create them.

Maybe this is something the Kendo guys can fix - not try to re-Kendize (just came up with that ;) the control in such cases like yours but a simple check like this should do the trick for you.
0
Jerrie Pelser
Top achievements
Rank 1
answered on 05 Jan 2012, 08:18 AM
In the end I basically just removed the data-* tag before calling the relevant kendo...() method.  This way the control would not be processed the second time around, e.g.

$('input[data-ui-datepicker]').each(function () {
            $(this).removeAttr('data-ui-datepicker');
            $(this).kendoDatePicker();
        });

Thanks
Tags
General Discussions
Asked by
Jerrie Pelser
Top achievements
Rank 1
Answers by
Vesselin Obreshkov
Top achievements
Rank 2
Jerrie Pelser
Top achievements
Rank 1
Share this question
or