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

Data Source empty array "[]" parsed as string by initWidget

1 Answer 103 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
RAC
Top achievements
Rank 1
RAC asked on 06 Feb 2017, 01:34 AM

We've recently undertaken an upgrade from Kendo UI 2013.2.716 to 2016.3.1118 and we've noticed some issues for our drop down lists. Some of our scenarios call for drop down lists with empty ("[]") data sources until other operations cause them to be filled, or they remain hidden.

Upon changing versions we've noticed that upon the initWidget method being called for that drop down list, the data source is being parsed as a string ("[]") when previously it was being recognised as an empty array. Some investigation and comparison of the two versions led me to a particular regular expression that had changed between the versions in parseOption:

2013 - jsonFormatRegExp = /^\{(\d+)(:[^\}]+)?\}/

2016 - jsonFormatRegExp = /^\{(\d+)(:[^\}]+)?\}|^\[[A-Za-z_]*\]$/

In 2013 this was not matching the empty array "[]", causing the code path to return it from a function (well, an "evil") to the initWidget method - now that it's matching, however, it's passing the string value back which is causing errors later in the code with the [] being used in getter names. Is there another way we should be populating this field? How can we get this version to recognise this value as the empty array it was intended to be?

 <input class=" roadmap" data-option-label="Select" data-role="dropdownlist" data-source="[]" data-text-field="Text" data-value-field="Value" id="xxx" name="yyy" style="width:100%;" type="text" value="" />

1 Answer, 1 is accepted

Sort by
0
Veselin Tsvetanov
Telerik team
answered on 07 Feb 2017, 01:46 PM
Hi,

Here you will find a simple Dojo sample, demonstrating two possible approaches to pass empty data to the DropDownList. You could either pass an empty string:
<input data-role="dropdownlist"
       data-source=""

or you could bind the source to an empty array in the ViewModel:
<input data-role="dropdownlist"
............
       data-bind="value: selectedProduc
                  source: products"
/>

I hope, that the above helps you. In case you have any further questions, please do not hesitate to contact us.

Regards,
Veselin Tsvetanov
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Data Source
Asked by
RAC
Top achievements
Rank 1
Answers by
Veselin Tsvetanov
Telerik team
Share this question
or