What I'm trying to do is I have 2 ComboBoxes that are setup in a Cascading relationship. What I am not able to get working is that when 1 option is selected in the first ComboBox the cascaded ComboBox should ONLY allow choices from the Items list it is populated with. When a 2nd option is selected in the first ComboBox(i.e. Other) the cascaded ComboBox should allow ANY text to be entered.
How can I achieve this? Below is my View and Controller in question.
VIEW:
CONTROLLER:
How can I achieve this? Below is my View and Controller in question.
VIEW:
<
div
class
=
"form-group"
>
@Html.LabelFor(model => model.locationCode, new { @class = "control-label col-md-2" })
<
div
class
=
"col-md-10"
>
@(Html.Kendo().ComboBox()
.Name("locationCode")
.Filter(FilterType.Contains)
.DataTextField("Text")
.DataValueField("Value")
.BindTo(Model.Locations)
.Suggest(true)
)
@Html.ValidationMessageFor(model => model.locationCode)
</
div
>
</
div
>
<
div
class
=
"form-group"
>
@Html.LabelFor(model => model.loadType, new { @class = "control-label col-md-2" })
<
div
class
=
"col-md-10"
>
@(Html.Kendo().ComboBox()
.Name("loadType")
.Filter(FilterType.Contains)
.DataTextField("Text")
.DataValueField("Value")
.BindTo(Model.LoadTypes)
.Suggest(true)
)
@Html.ValidationMessageFor(model => model.loadType)
</
div
>
</
div
>
<
div
class
=
"form-group"
>
@Html.LabelFor(model => model.loadDescrip, new { @class = "control-label col-md-2" })
<
div
class
=
"col-md-10"
>
@(Html.Kendo().ComboBox()
.Name("loadDescription")
.Filter(FilterType.Contains)
.DataTextField("DocCode")
.DataValueField("DocCode")
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetCascadeDocumentNumbers", "DockDoor")
.Data("filterLoadDescription");
})
.ServerFiltering(true);
})
.Enable(false)
.AutoBind(false)
.CascadeFrom("loadType")
)
<
script
>
function filterLoadDescription() {
return {
locCode: $("#locationCode").val(),
loadType: $("#loadType").val(),
docNumFilter: $("#loadDescription").data("kendoComboBox").input.val()
};
}
</
script
>
@Html.ValidationMessageFor(model => model.loadDescrip)
</
div
>
</
div
>
public
JsonResult GetCascadeDocumentNumbers(
string
locCode,
string
loadType,
string
docNumFilter)
{
if
(loadType !=
"OPEN"
&& loadType !=
"GENERIC"
)
{
var docNums = db.GetCurrentDocumentNumbers(locCode, loadType).AsEnumerable();
if
(!
string
.IsNullOrWhiteSpace(docNumFilter))
{
docNums = docNums.Where(x => x.Contains(docNumFilter));
}
return
Json(docNums.Select(x =>
new
{ DocCode = x.ToString() }), JsonRequestBehavior.AllowGet);
}
return
Json(
string
.Empty, JsonRequestBehavior.AllowGet);
}