Your online examples need explanation. Just putting the code out there is not considered best practice. This example:
https://demos.telerik.com/aspnet-mvc/combobox/cascadingcombobox
I'm trying to get the cascading going using ASP.NET Core MVC. I am able to get the first combo box working. But, the cascade action doesn't work. Your example references objects that have no definition so I'm lost. For example:
productFilter: $("#products").data("kendoComboBox").input.val()
What is the "kendoComboBox" referring to? What is it and where did it originate?
Here is my attempt:
<
div
class
=
"form-group"
>
<
label
asp-for
=
"DefaultCountryCode"
class
=
"control-label"
></
label
><
br
/>
@(Html.Kendo().ComboBoxFor(x => x.DefaultCountryCode)
.Placeholder("Select Country...")
.DataTextField("Name")
.DataValueField("Context")
.Filter(FilterType.Contains)
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetCountries", "Persons");
});
})
.HtmlAttributes(new { style = "width: 100%" }))
</
div
>
<
div
class
=
"form-group"
>
<
label
asp-for
=
"DefaultTimeZoneId"
class
=
"control-label"
></
label
><
br
/>
@(Html.Kendo().ComboBoxFor(x => x.DefaultTimeZoneId)
.Placeholder("Select Time Zone...")
.DataTextField("Comment")
.DataValueField("ZoneId")
.Filter(FilterType.Contains)
.DataSource(source =>
{
source.Read(read =>
{
read.Action(
"GetTimeZoneByCountryCodeAsync",
"Persons")
.Data("filterZones");
});
})
.HtmlAttributes(new { style = "width: 100%" })
.Enable(false)
.AutoBind(false)
.CascadeFromField("DefaultCountryCode")
)
<
script
>
function filterZones() {
return {
countries: $("#countries").val(),
productFilter: $("#timeZones").data("kendoComboBox").input.val()
};
}
</
script
>
</
div
>
The "DefaultCountryCode" combobox is working.
Your example seems to refer to the other combobox using the value in the "combobox.name" property. However, I tie this to the model using ComboBoxFor.
2nd ComboBox:
- I need the ComboBox1.DataValueField("Context") value to be used to submit the value to ComboBox2
- How do I tie the 2nd to the 1st combobox in this scenario? I'm guessing by using the "combobox.CascadeFromField" approach.
- The example sets the Enable property to false and AutoBind to false. Why? Give me documentation.
- The example references the filterProducts (filterZones) script to feed the read.Action.Data combobox.Datasource. When doing "combobox.CascadeFromField", is this necessary? My script isn't working and the Action is never fired.
Thanks for your help,
Joel