Unplanned
Last Updated: 04 Nov 2019 15:41 by ADMIN
Ronny
Created on: 31 Oct 2019 20:15
Category: MultiSelect
Type: Bug Report
0
MultiSelect setValue seems to convert Strings with leading zeros to Integer when parsing the key field.

Dear support team

 

I have an interesting phenomenon. We are using a MultiSelect widget with remote data binding. In theory, the data looks like this:

Key: 099

Value: Test1

Key: 100

Value: Test2

etc.

I can select all values just fine and they are posted to the form on the receiving end. When reloading the form, we pre-populate the selected items, by calling ->setValue() with an Array of strings: 099,100.

However, the generated Javascript code for the multiselect will change that to [99,100]. So the 099 will not get selected when shown.

Is this something I can avoid? Do I need to specify anything special for the Key column (so far I have only specified the name of the field and marked it as an IDcolumn).

 

Here is the generated javascript code, as you can see, the value is set to 99, but gets passed in the PHP array as '099':

 <select id="berufsgruppeMultiSelect[]" name="berufsgruppeMultiSelect[]" style="width:500px;"></select><script>jQuery(function(){jQuery("#berufsgruppeMultiSelect\\[\\]").kendoMultiSelect({"dataSource":{"type":"odata-v4","serverFiltering":true,"serverSorting":true,"serverPaging":true,"transport":{"read":{"url":function(data) {return "http://aiislab1.bsl.ch.almanid.com:8180/iswebservice/OData4Service.svc/Attributes('687')/CTVRecords?lang=en&$select=V_Long&SESSIONID=" + encodeURIComponent(cookieSessionID) + "";},"contentType":"application\/json;odata.metadata=minimal","dataType":"json","type":"GET"},"parameterMap":function(options, type) {
if (type === 'read') {
if (options.filter) {
for(var index in options.filter.filters) {
var Filter = options.filter.filters[index];
Filter.value = boolean2string(Filter.value);

if ($.isArray(Filter.filters)) {
for(var arrayIndex in Filter.filters) {
var ArrayFilter = Filter.filters[arrayIndex];
ArrayFilter.field = 'tolower(' + ArrayFilter.field + ')';
ArrayFilter.value = ArrayFilter.value.toLowerCase();
}
} else {
Filter.field = 'tolower(' + Filter.field + ')';
Filter.value = Filter.value.toLowerCase();
}
}
} else {
                    options.filter = {logic: 'and', filters: [{field: 'tolower(Language)', operator: 'contains', value: 'en'}]};
                }
if (options.sort) {
var sortCount = 0;
for(var index in options.sort) {
var Sorter = options.sort[index];
sortCount = 1;

}
}
if (typeof sortCount === 'undefined' || sortCount === 0) {
options.sort = [{field: 'V_Long', dir: 'asc'}];
}
}
return kendo.data.transports['odata-v4'].parameterMap(options, type);}
},"schema":{"model":{"fields":[{"field":"Key"},{"field":"V_Long"}],"id":"Key"}}},"dataTextField":"V_Long","dataValueField":"Key","value":[99],"valuePrimitive":true,"filtering":function (e) {
            if (e.filter) {
                var value = e.filter.value
                var newFilter = {
                    logic: 'and',
                    filters: [
                        { field: 'tolower(Language)', operator: 'contains', value: 'en' },
                        {
                            logic: 'or',
                            filters: [
                                { field: 'id', operator: 'contains', value: value },
                                { field: 'V_Long', operator: 'contains', value: value }
                            ]
                        }
                    ]
                }
                e.sender.dataSource.filter(newFilter)
                e.preventDefault()
            }
            e.preventDefault()
        },"placeholder":"alle Berufsgruppen","itemTemplate":"#: id# (#: V_Long#)","tagTemplate":"#: id# (#: V_Long#)"});});</script>

 

Thank you for your advice.

Yours,

Ronny

4 comments
ADMIN
Misho
Posted on: 04 Nov 2019 15:41

Hello,

Regards,
Misho
Progress Telerik

Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
ADMIN
Misho
Posted on: 04 Nov 2019 15:38

Hello Ronny,

Thank you for the additional information you have provided. We reviewed the issue in more details and could confirm the problem is related to the Kendo PHP wrapper. It is related to the following code:which returns the value without the leading zeros: json_encode($value, JSON_NUMERIC_CHECK ) and I've logged this in our public backlog:

https://github.com/telerik/kendo-ui-core/issues/5384

As a small token of gratitude for your report and research I'm updating the Telerik points of your account.

Best Regards,
Misho
Progress Telerik

Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Ronny
Posted on: 01 Nov 2019 15:29
Dear Misho

Thank you for taking on my service request. I can assure you, that the PHP variable is correctly set to ‘099’, please take a look at our PHP code:

        if ($this->readOnly) {
            $result = "<select id=\"" . $this->name . "\" style=\"" . $this->style . "\" size='3' readonly>";
            if (isset($this->value)) {
                foreach ($this->value as $code) {
                    $result .= "<option>" . $code . " (" . $this->getValueFromKey($code) . ")</option>";
                }
            } else {
                $result .= "";
            }
            $result .= "</select>";
            return $result;
        } else {
            foreach ($this->fieldValues as $fieldValues) {
                $field = new \Kendo\Data\DataSourceSchemaModelField($fieldValues['name']);

                $this->model->addField($field);

                // handle id field for model
                if (isset($fieldValues['isIDField'])) {
                    if ($fieldValues['isIDField'] === TRUE) {
                        $this->model->id($fieldValues['name']);
                    }
                }
            }

            $this->schema->model($this->model);
            $this->finishDataSource();
            $this->dataSource->schema($this->schema);
            $this->multiSelect->dataSource($this->dataSource);

            $this->multiSelect->dataTextField($this->dataTextField)
                ->dataValueField($this->dataValueField)
                ->dataSource($this->dataSource)
                ->attr("style", $this->style)
                ->value($this->value)
                ->valuePrimitive(true);


If we are in readOnly mode, the HTML code clearly gets “099” as the $code printed. As soon as we pass it into ->value($this->value), it will end up as 99 in HTML. So I assume, that the conversion is happening inside of Kendo UI PHP wrapper.


Yours,

Ronny
ADMIN
Misho
Posted on: 01 Nov 2019 15:17

Hi Ronny,

This behavior looks like related to how PHP formats numbers with leading zero. Here are some links with discussions on the matter from the community:

https://stackoverflow.com/questions/4139301/php-0-as-a-string-with-empty

https://stackoverflow.com/questions/18148486/how-to-keep-leading-zeros-in-php-integer 

https://stackoverflow.com/questions/1699958/formatting-a-number-with-leading-zeros-in-php 

 

We will need some time to research the issue in more details and will get back to you a as soon as we have more information.

 

Best Regards,
Misho
Progress Telerik

Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.