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

[Solved] JS error when initializing toolbar with zero items

6 Answers 119 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Nicholas
Top achievements
Rank 1
Nicholas asked on 09 Oct 2014, 03:58 PM
Hi,

We have a grid with a toolbar template containing a KendoToolBar object that can potentially have zero items in it (depending on the user account's security settings). If this happens, we get an error thrown from kendo.web.js and the page fails to load.

buttonGroup: {
    base: function (options, initializer, element) {
        var items = options.buttons,
            item;
 
        element.data({ type: "buttonGroup" });
        element.attr(KENDO_UID_ATTR, options.uid);
 
        for (var i = 0; i < items.length; i++) {
            if (!items[i].uid) {
                items[i].uid = kendo.guid();
            }
            item = initializer($.extend({mobile: options.mobile}, items[i]));
            item.appendTo(element);
        }

'items' is undefined so an exception is thrown on the for loop. Is this a known issue?

Thanks,
Nick

6 Answers, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 13 Oct 2014, 09:05 AM
Hello Nicholas,

I tried to reproduce the behaviour in a sample page but to no avail. Could you please check it and let me know what I am missing?
By default the items option is set to empty array if not defined by the user:
In addition during the widget initialization items are rendered only if the `items` are set:
The core you referenced is related to the ButtonGroup component. A ButtonGroup cannot be initialized without any child buttons as it does not make sense to have a "group of nothing". If in your case the ButtonGroup does not have any items please do not initialize it.

Regards,
Alexander Valchev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Nicholas
Top achievements
Rank 1
answered on 21 Oct 2014, 05:35 PM
Hi Alexander,

Sorry for the late reply -- last week was very busy. Yes, the ButtonGroup is the issue. We could of course check that at least one of the conditions is met before initializing it at all, but it seems like that would be easy to forget at some point and would be a quick fix from your end. If not, we can proceed with this workaround.

If it helps at all, the JavaScript code that the MVC wrapper generated (which I forgot to mention before we are using) is in this example:

http://dojo.telerik.com/IzeTe

Thanks,
Nick

0
Alexander Valchev
Telerik team
answered on 24 Oct 2014, 06:51 AM
Hello Nicholas,

Could you please explain what you expect to happen when a button group with no buttons is defined? How the rendered by the widget component should look like? Should the ToolBar render a ButtonGroup at all?

Regards,
Alexander Valchev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Nicholas
Top achievements
Rank 1
answered on 27 Oct 2014, 03:24 PM
I think I'd expect it to not render the group at all, but I'd be fine with it rendering empty space as well.

Thanks,
Nick
0
Accepted
Alexander Valchev
Telerik team
answered on 29 Oct 2014, 11:41 AM
Hello Nicholas,

Thank you the feedback.

We will change the current behaviour of the widget so when a ButtonGroup with no buttons is present the widget will not throw JS error and will not render the group at all.
The fix will be included in the next internal and Q3 2014 official build.

Regards,
Alexander Valchev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Nicholas
Top achievements
Rank 1
answered on 29 Oct 2014, 02:57 PM
Great, thanks!
Tags
Grid
Asked by
Nicholas
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Nicholas
Top achievements
Rank 1
Share this question
or