Hello,
I have a dropdownlist where I am using the .Select() and .Close() events. What I'm doing is changing the background colors of the dropdownlists when there is something in the list selected. This is so there's a visual indication for the user. If the user clicks off the box, it will remain colorized if there's a selection made. If there isn't, then it will return to the default color. Attached image (ex-01)
For some reason, this doesn't work if I have a different .DataTextField vs. .DataValueField. I have done this because I need to have the list display only a pre-formatted first name for the user. (e.g. John, instead of John Smith or JOHN SMITH). So in the cases where I have pre-formatting, it will colorize the dropdown correctly, but it does not remove it when I return to selectedIndex = 0 like the rest of the dropdowns. Attached image (ex-02).
The only difference in the code is that the .DataTextField("SomeFieldDisplay") and .DataValueField("SomeField") for the items that DO NOT. For the ones that work, it's .DataTextField("SomeField") and .DataValueField("SomeField"). I'm pretty puzzled by this one. My code is below. Thanks!
<script type=
"text/javascript"
>
function
onSelect(e) {
e.sender.wrapper.children(0).addClass(
"custom-dropdown"
);
}
function
onClose(e) {
if
(e.sender.selectedIndex < 1) {
e.sender.wrapper.children(0).removeClass(
"custom-dropdown"
);
}
}
</script>
<style>
html .k-widget .custom-dropdown {
background-color
:
#00B312
;
}
</style>
@( Html.Kendo().DropDownList()
.Name("ddlTopics")
.DataTextField("TopicTitle")
.DataValueField("TopicTitle")
.DataSource(ds =>
{
ds.Read(read =>
{
read.Action("GetAllTopicsByTitle", "Hierarchy");
});
})
.Events(e =>
{
e.Select("onSelect").Close("onClose");
})
.OptionLabel("--Select Topic--")
)
@(Html.Kendo().DropDownList()
.Name("ddlTopicOwner")
.DataTextField("TopicOwnerDisplay")
.DataValueField("TopicOwner")
.DataSource(ds =>
{
ds.Read(read =>
{
read.Action("GetAllTopicsByOwner", "Hierarchy");
});
})
.Events(e =>
{
e.Select("onSelect").Close("onClose");
})
.OptionLabel("--Select Topic Owner--")
)