
How can I allow blank selection in a kendoDropDownList?
There is an example with the combobox but wants to add this behavior within the kendoDropDownList.
5 Answers, 1 is accepted
Check the optionLabel functionality.
Georgi Krustev
the Telerik team
But if you want to have a blank selection, how do you proceed?
The use could select something or put back a blank value.
Also, if I press the Delete key, it doesn't always put back the optionLabel selection. I experience this behavior in 2012.1.229.beta.
Thank you for getting back to us. By design the value of the optionLabel is a blank text and we do not create it if the value of the option is an empty text. If you need to add optionLabel without a text then you should set the option to " ":
$(
"#ddl"
).kendoDropDownList({
optionLabel:
" "
});
Kind regards,
Georgi Krustev
the Telerik team
In order to avoid this behavior you will need to modify the content of the first LI element:
$(
"#ddl"
).data(
"kendoDropDownList"
).one(
"open"
,
function
() {
$(
this
.ul[0].firstChild).html(
" "
);
});
Greetings,
Georgi Krustev
the Telerik team
I was not able to observe the erroneous behavior locally. I make a screencast, which shows by observation. Let me know if I am missing something.
Georgi Krustev
the Telerik team
In general the DropDownList widget is not designed to show empty OptionLabel. Nevertheless you can achieve your goal using custom template:
template:
"#= data.name.replace(' ', ' ') #"
Kind regards,
Georgi Krustev
the Telerik team
In regards to the workaround, has anyone gotten this to work? I haven't tried the script approach as it appears from the thread this did not work, however the template approach also does not appear to work, simply returning this error:
"Uncaught TypeError: Cannot call method 'replace' of undefined"
Any help would be much appreciated!
The link seems valid at my end: screenshot.
Regards,
Ivan Danchev
Progress Telerik
I was replying to the post with the kendo documentation link about optionLabel, your forum put my reply at the bottom, under your post. This is the link I was trying to open.
http://www.kendoui.com/documentation/ui-widgets/dropdownlist/configuration.aspx#optionLabel
Is redirected to this link below which is the main Kendo-ui product description. Even though I am currently logged into the Telerik site with an account with an active subscription.
https://www.telerik.com/kendo-ui?utm_expid=.QZlGnZzwQVuthJ0mrhuF3A.0&utm_referrer=#optionLabel
The correct kendo-ui OptionLabel api link is here.
https://docs.telerik.com/kendo-ui/api/javascript/ui/dropdownlist#configuration-optionLabel
Its not just this forum post, I have clicked on many broken documentation links in your forum over the last few months.
Thank you for the clarification. Indeed old links to kendoui.com are currently redirected to telerik.com. I notified the team about the redirects and suggested changing them to corresponding pages from the Kendo UI Documentation site.
Regards,
Ivan Danchev
Progress Telerik
Here is a simple jsFiddle demo, which shows how to achieve your goal just using custom template.
Georgi Krustev
the Telerik team
Code follows.
Jim Stanley
Blackboard Connect
<div class="formField contactGender contactInfoContainer">
@Html.LabelFor(model => model.Gender)
@(Html.Kendo().DropDownListFor(model => model.Gender)
.BindTo(new SelectList(Model.Genders, "key", "value"))
.HtmlAttributes(new { @class = "dropDownList" })
.Enable(!Model.ViewOnly)
.DataTextField("Text")
.DataValueField("Value")
.OptionLabel(" ")
.Template("#= data.Text #")
)
@Html.ValidationMessageFor(model => model.Gender)
</div>
Could you elaborate more on "can you please replicate the standard HTML behavior" ? For now you will need to define the aforementioned template, which will allow you to define an empty item in the widget.
Georgi Krustev
Telerik
Here is the updated jsFiddle demo. You can specify an empty option without setting a specific template.
Note that it uses the Q3 2013 BETA bits.
Georgi Krustev
Telerik

Why can't you simply specify optionLabel: " " ? This way you don't need to mess around with templates where you have to mention data text field again
Artem

div.contactInfoContainer > .k-dropdown
{
display: block;
height:25px;
}

Just in case someone stumbles across this thread because they're still using a years-old version of kendo, when specifying OptionLabel(" ") with the MVC helper, the CSS approach worked for us via:
#id-list > .k-list > .k-item
{
display
:
block
;
height
:
25px
;
}
until one of the drop down lists included items with hyphens in them, which caused them to be listed (and selectable) on separated lines (e.g. Semi-Annually was displayed as Semi- on one line and Annually on the next, both individually selectable). First tried changing the display as in
#id-list > .k-list > .k-item
{
display
:
table-row
;
height
:
25px
;
}
which got them to display properly, but in IE and chrome, the blank item was no longer selectable. So instead of CSS for that drop down, had to go with the javascript option instead:
$(document).ready(
function
() {
setTimeout(
function
() {
var
ddl = $(
"#id"
).data(
"kendoDropDownList"
);
$(ddl.ul[0].firstChild).html(
" "
);
}, 10);
});
Hope this helps someone.
You'll also find your Telerik points updated for your contribution.
--Marin