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.
This should work:
$("#txtQPLPickupFrom").data("kendoDropDownList").value(-1);
Here is a fiddle (not mine): http://jsfiddle.net/EaNm4/124/
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)
.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With