Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I reset a KendoDropDownList selected index back to -1 (nothing selected)

Tags:

kendo-ui

When a KendoDropDownList is created it's initial index is set to -1 and the text is empty.

IE: $("#txtQPLPickupFrom").data("kendoDropDownList").select() would return a -1.

When a selection is made, the select() returns the selected index (0,1,2,3...).

My question is, I want to return the selected index back to -1 when I am displaying an new record entry where the user has not selected a value. Trying to use .select(-1) does not seem to work. So it there a way to restore the initial selection to nothing (-1) after it's already had a value.

like image 795
George Avatar asked May 20 '13 20:05

George


3 Answers

This should work:

$("#txtQPLPickupFrom").data("kendoDropDownList").value(-1);

Here is a fiddle (not mine): http://jsfiddle.net/EaNm4/124/

like image 176
Lars335 Avatar answered Nov 19 '22 06:11

Lars335


The kendo dropdown will always default to the first item in its datasource. You could configure the dropdown to use optionLabel: ' ' (a space), which will cause the initial value selected to have no text.

You could then reset the selection to this value with .select(0).

like image 36
Szilard Muzsi Avatar answered Nov 19 '22 08:11

Szilard Muzsi


This seems to work: (I have to do more testing)

var txtQPLPickupFrom = $("#txtQPLPickupFrom").data("kendoDropDownList");
txtQPLPickupFrom.text(txtQPLPickupFrom.options.optionLabel);
txtQPLPickupFrom.element.val("");
txtQPLPickupFrom.selectedIndex = -1;
like image 3
George Avatar answered Nov 19 '22 06:11

George