I have a kendo form with two drop down list editors.
How can I from Javascript set the selected value of one of the drop downs.
Both drop downs are using server side filtering .
There is a possibility that the value i need to set is not in the already pulled data , but it is guaranteed to be in the full datasource.
Any direction would be appreciated.
@(Html.Kendo().Form<KitMasterViewModel>()
.Name("KitInfoForm")
.HtmlAttributes(new { action = @Url.Action("ValidationKitMaster", "KitsOverview"), method = "POST" })
.FormData(Model)
.Layout("grid")
.Grid( c => c.Cols(2).Gutter(4))
.Validatable(v =>
{
v.ValidateOnBlur(true);
v.ValidationSummary(vs => vs.Enable(false));
})
.Items(items =>
{
items.AddGroup()
.Label("Kit Information")
.Items(i =>
{
i.Add()
.Field(f => f.SeqKit)
.Label(l => l.Text("Kit Number:"));
i.Add()
.Field(f => f.DateSchedule)
.Label(l => l.Text("Date Required"));
i.Add()
.Field(f => f.KitQty)
.Editor(E =>
{
E.NumericTextBox<int>()
.HtmlAttributes(new {style = "text-align:right" })
.Format("N0");
})
.Label(l => l.Text("Kit Quantity:"));
i.Add()
.Field(f => f.PickOrder)
.Label(l => l.Text("Pick Order:"))
.Editor(E => {
E.DropDownList()
.DataTextField("Text")
.DataValueField("Value")
.BindTo(new List<SelectListItem>()
{
new SelectListItem()
{
Text="Lowest Quantity",
Value=$"{(int)InoAutoBusiness.Enums.EPickPackageOrder.LowestQty}",
},
new SelectListItem()
{
Text="FIFO Order",
Value=$"{(int)InoAutoBusiness.Enums.EPickPackageOrder.FIFO}"
},
new SelectListItem()
{
Text="Match Quantity",
Value=$"{(int)InoAutoBusiness.Enums.EPickPackageOrder.ClosestMatch}"
},
new SelectListItem()
{
Text="Custom Order",
Value=$"{(int)InoAutoBusiness.Enums.EPickPackageOrder.Custom}"
},
});
});
i.Add()
.Field(f => f.ID)
.Label(" ")
.EditorTemplate("<input name='ID' type='hidden' />");
});
items.AddGroup()
.Label("Source")
.Items(i =>
{
i.Add()
.Field(f => f.IDBom)
.Label("Assigned Bill of Material")
.Editor(e =>
{
e.DropDownList()
.DataValueField("IDBom")
.DataTextField("LongName")
.HtmlAttributes(new { style = "width:100%"})
.Filter("contains")
.Events(item => item.Change("BillChanged"))
.MinLength(3)
.Height(520)
.Template("<table><tr><td style='width:200px' >#: data.PartNumber #</td><td style='width:50px'>#: data.Revision #</td></tr></table>")
.DataSource(
source =>
{
source.Custom()
.ServerFiltering(true)
.ServerPaging(true)
.PageSize(80)
.Type("aspnetmvc-ajax")
.Transport(transport =>
{
transport.Read("GetBOMMasters", "BillOfMaterial");
})
.Schema(schema =>
{
schema.Data("Data") //define the [data](https://docs.telerik.com/kendo-ui/api/javascript/data/datasource#configuration-schema.data) option
.Total("Total"); //define the [total](https://docs.telerik.com/kendo-ui/api/javascript/data/datasource#configuration-schema.total) option
});
}
);
});
i.Add()
.Field(f => f.IDAVL)
.Label("Assigned Constraint")
.Editor(e =>
{
e.DropDownList()
.Name("ddlAVL")
.HtmlAttributes(new { })
.DataTextField("NameAVL")
.DataValueField("IDAVL")
.HtmlAttributes(new { style = "width:100%" })
.Height(520)
.MinLength(3)
.Filter(FilterType.Contains)
.DataSource(
source =>
{
source.Custom()
.ServerFiltering(true)
.ServerPaging(true)
.PageSize(80)
.Type("aspnetmvc-ajax") //Set this type if you want to use DataSourceRequest and ToDataSourceResult instances
.Transport(transport =>
{
transport.Read("GetAVLMasters", "BOMEdit");
})
.Schema(schema =>
{
schema.Data("Data") //define the [data](https://docs.telerik.com/kendo-ui/api/javascript/data/datasource#configuration-schema.data) option
.Total("Total"); //define the [total](https://docs.telerik.com/kendo-ui/api/javascript/data/datasource#configuration-schema.total) option
});
}
);
});
});
})
)
<script type="text/javascript">
$(document).ready(function () {
$("input[type='text'], textarea").attr('spellcheck', false);
});
function BillChanged(e) {
var ddl = e.sender;
var selectedValue = ddl.value();
$.ajax({
url: "@Url.Action("GetBOMMasters", "BillOfMaterial",new { id = UrlParameter.Optional, operation = UrlParameter.Optional })" + "/" + selectedValue,
type: 'POST',
contentType: 'application/json;',
data: JSON.stringify({ id: selectedValue }),
success: function (bom) {
if (bom.Data.length>0) {
var idAVL = bom.Data[0].IDAVL;
// I need to set the value of ddlAVL to idAVL here
// but i am at a loss to how to do it
debugger;
}
}
});
}
function NavigateComponents() {
location.href = "@Url.Action("KitsOverview", "KitsOverview",new {id=Model.ID, operation = "components"})";
}
function NavigateKitInfo() {
location.href = "@Url.Action("KitsOverview", "KitsOverview",new { id = Model.ID, operation = "info"})";
}
function NavigateOverview() {
location.href = "@Url.Action("KitsOverview", "KitsOverview", new { id = UrlParameter.Optional, operation = UrlParameter.Optional})";
}
</script>