telerik / kendo-ui-core

An HTML5, jQuery-based widget library for building modern web apps.
http://www.telerik.com/kendo-ui
Other
2.54k stars 1.91k forks source link

MultiSelect on adding a new item the dataSource requestEnd event args return "read" type of request #5591

Closed IvanDanchev closed 4 years ago

IvanDanchev commented 4 years ago

Bug report

When a new item is added and the dataSource's sync method is called, the requestEnd event handler data (arg.type) returns the type of request as "read", instead of "create". As a result, the Add new item demo does not work as expected, because it has a check for the type of the request in the requestEnd handler, and expects the request to be "create". Since the request type comes out as "read" the logic for selecting the newly added item is not executed.

In previous versions the request has been correctly identified as "create". The issue is exhibited only in the MultiSelect. The ComboBox and the DropDownList return the request as "create".

This behavior has been introduced in R3 2017. Reproducible in Chrome, Firefox and Chromium Edge. Not reproducible in IE11 and Spartan Edge.

As a workaround the addNew function can be modified as shown below:

function addNew(widgetId, value) {
    var widget = $("#" + widgetId).getKendoMultiSelect();
    var dataSource = widget.dataSource;

    if (confirm("Are you sure?")) {
        dataSource.add({
            ProductID: 0,
            ProductName: value
        });

        dataSource.one("sync", function() {
          var index = dataSource.view().length - 1;
          var newValue = dataSource.at(index).ProductID;

          widget.value(widget.value().concat([newValue]));
        });

        dataSource.sync();
    }
}

Reproduction of the problem

Dojo example.

  1. Open the browser's console.
  2. Focus the input and type in some random text.
  3. Click the button in the popup to add a new item.
  4. The type of the request returned by the requestEnd event data is logged in the console.

Current behavior

The event data returns "read" as the type of the request.

Expected/desired behavior

The event data returns "create" as the type of the request.

Environment

veselints commented 4 years ago

The unexpected result is caused by the fact that upon blurring the MultiSelect input field, the filter text is being cleared. Upon clearing the filter, the MultiSelect should return the full data in the DataSource to its view. Therefore, the requestEnd event gents fired with type read. After that, the requestEnd event also gets fired with type create. The change is introduced with the following fix: https://github.com/telerik/kendo/commit/ceca71b61fe6041575813dde40df73f63ea7f95f#diff-d49530520f78dc5b384ff72c7fc5a08c

Having that said, I will change the implementation of the demos to respect the above (expected) behavior of the MultiSelect widget.

Dimitar-Goshev commented 4 years ago

The following updated Dojo snippet shows the proper implementation. The change is as follows:

fix(demo)_ MultiSelect Add new item demo to respect the thrown events… · telerik_kendo@80dc2cb - Mozilla Firefox 2020-02-14 14 31 12