Skip to content

Commit

Permalink
Force VirtualList to reset its value when 'null' is passed to the val…
Browse files Browse the repository at this point in the history
…ue method. Fix telerik#1017
  • Loading branch information
valchev committed Oct 8, 2015
1 parent 46c744c commit 7b5b3ee
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/kendo.virtuallist.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,10 @@ var __meta__ = { // jshint ignore:line
return that._values.slice();
}

if (value === null) {
value = [];
}

value = toArray(value);

if (that.options.selectable === "multiple" && that.select().length && value.length) {
Expand Down
48 changes: 48 additions & 0 deletions tests/virtuallist/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,23 @@
});
});

asyncTest("when null is passed to the value method all values are cleared", 3, function() {
var virtualList = new VirtualList(container, $.extend(virtualSettings, {
selectable: "multiple",
value: [1, 2, 3]
}));

asyncDataSource.read().then(function() {
virtualList.bind("change", function() {
start();
ok(true, "change is fired");
equal(this.value().length, 0);
equal(this.selectedDataItems().length, 0);
});
virtualList.value(null);
});
});

asyncTest("when empty array is passed to the value method removed items are available in the change event", 1, function() {
var virtualList = new VirtualList(container, $.extend(virtualSettings, {
selectable: "multiple",
Expand All @@ -899,6 +916,21 @@
});
});

asyncTest("when null is passed to the value method removed items are available in the change event", 1, function() {
var virtualList = new VirtualList(container, $.extend(virtualSettings, {
selectable: "multiple",
value: [1, 2, 3]
}));

asyncDataSource.read().then(function() {
virtualList.bind("change", function(e) {
start();
equal(e.removed.length, 3);
});
virtualList.value(null);
});
});

asyncTest("value method clears previous values and dataItems (single selection)", 3, function() {
var virtualList = new VirtualList(container, $.extend(virtualSettings, {
selectable: true,
Expand Down Expand Up @@ -974,6 +1006,22 @@
});
});

asyncTest("valueDeffered is resolved immediately if null is passed", 2, function() {
var count = 1;
var virtualList = new VirtualList(container, $.extend(virtualSettings, {
selectable: "multiple",
value: [1, 2, 3]
}));

asyncDataSource.read().then(function() {
virtualList.value(null).done(function() {
start();
ok(true, "done callback");
equal(virtualList.value().length, 0);
})
});
});

asyncTest("valueDeffered is resolved immediately if value mapper returns an empty array", 1, function() {
var count = 1;
var virtualList = new VirtualList(container, $.extend(virtualSettings, {
Expand Down

0 comments on commit 7b5b3ee

Please sign in to comment.