Skip to content

Commit d2b7c8d

Browse files
committed
Problem with reverting to blank state. Fixes telerik#638
1 parent 3f8dd83 commit d2b7c8d

File tree

3 files changed

+67
-4
lines changed

3 files changed

+67
-4
lines changed

src/kendo.autocomplete.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ var __meta__ = {
265265
if (!length || length >= options.minLength) {
266266
that._open = true;
267267

268+
that.listView.filter(true);
268269
that._filterSource({
269270
value: ignoreCase ? word.toLowerCase() : word,
270271
operator: options.filter,
@@ -419,6 +420,12 @@ var __meta__ = {
419420

420421
that._angularItems("compile");
421422

423+
//reset list value
424+
that.listView.value([]);
425+
that.listView.focus(-1);
426+
427+
that.listView.filter(false);
428+
422429
that._calculateGroupPadding(that._height(length));
423430

424431
if (popup.visible()) {
@@ -454,13 +461,15 @@ var __meta__ = {
454461
}
455462

456463
that._makeUnselectable();
457-
458464
that._hideBusy();
465+
459466
that.trigger("dataBound");
460467
},
461468

462469
_listChange: function() {
463-
this._selectValue(this.listView.selectedDataItems()[0]);
470+
if (!this.listView.filter()) {
471+
this._selectValue(this.listView.selectedDataItems()[0]);
472+
}
464473
},
465474

466475
_selectValue: function(dataItem) {

src/kendo.list.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -1325,8 +1325,12 @@ var __meta__ = {
13251325
return result;
13261326
},
13271327

1328-
filter: function(isFilter) {
1329-
this._filtered = isFilter;
1328+
filter: function(filter) {
1329+
if (filter === undefined) {
1330+
return this._filtered;
1331+
}
1332+
1333+
this._filtered = filter;
13301334
},
13311335

13321336
select: function(indices) {

tests/autocomplete/filtering.js

+50
Original file line numberDiff line numberDiff line change
@@ -275,4 +275,54 @@ test("select item after filtering", function() {
275275
equal(autocomplete.value(), "foo2");
276276
});
277277

278+
test("AutoComplete does not revert input value on search", function() {
279+
var autocomplete = new AutoComplete(input, {
280+
dataTextField: "text",
281+
dataSource: {
282+
data: [
283+
{text: "foo", value: "1", parent: 1},
284+
{text: "foo1", value: "2", parent: 1},
285+
{text: "foo2", value: "3", parent: 1},
286+
{text: "foo3", value: "4", parent: 2},
287+
{text: "foo4", value: "5", parent: 2},
288+
{text: "foo5", value: "6", parent: 3},
289+
]
290+
},
291+
filter: "contains"
292+
});
293+
294+
autocomplete.search("foo1");
295+
autocomplete.ul.children(":first").click();
296+
297+
autocomplete.element.val("fo");
298+
autocomplete.search("fo");
299+
300+
equal(autocomplete.value(), "fo");
301+
});
302+
303+
test("AutoComplete resets list value on refresh", function() {
304+
var autocomplete = new AutoComplete(input, {
305+
dataTextField: "text",
306+
dataSource: {
307+
data: [
308+
{text: "foo", value: "1", parent: 1},
309+
{text: "foo1", value: "2", parent: 1},
310+
{text: "foo2", value: "3", parent: 1},
311+
{text: "foo3", value: "4", parent: 2},
312+
{text: "foo4", value: "5", parent: 2},
313+
{text: "foo5", value: "6", parent: 3},
314+
]
315+
},
316+
filter: "contains"
317+
});
318+
319+
autocomplete.search("foo1");
320+
autocomplete.ul.children(":first").click();
321+
322+
autocomplete.element.val("fo");
323+
autocomplete.search("fo");
324+
325+
equal(autocomplete.listView.value().length, 0);
326+
});
327+
278328
}());

0 commit comments

Comments
 (0)