javascript - Cascading ComboBox drops model binding after setting initial value empty -
my scenario:
cascading dropdowns ending combobox (partial view) used in master->details scenario kendo grid
ddl->ddl->ddl->cb
goal:
- on page load dropdownlists being initialized data 1 one default value, , combobox should stay empty
- on grid selecteditemchanged partial view being filled data , combobox should display appropriate element.
in case works follows:
- on page load combobox displays '0' (null suppose?)
- on selection change blinks selected value model.id , shows appropriate text
or if clear text/value propery of kendocombobox when parent dropdownlist data loaded:
- on page load combobox empty
- on selection change blinks above stays empty
if change combobox control 4th dropdownlist still "blinks" in works fine. selected item model preserved correctly in dropdown.
i cannot provide complete example because it's heavy don't think it's necessary.
this how lists data cascading. on parent's databound event .datasource.read() method of child called. nothing fancy.
function parentproductiddatabound() { var dropdownlist = $("#parentproductid").data("kendodropdownlist"); if (dropdownlist.value()) { onparentproductidchange(); } } function parentproductidchange() { onparentproductidchange(); } function onparentproductidchange() { var productcombobox = $("#productid").data("kendocombobox"); productcombobox.text(""); <- empty until combo populated productcombobox.value(""); productcombobox.enable(true); <- enable combo productcombobox.datasource.read(); <- populate combo }
and here code of combo itself
@(html.kendo().combobox() .name("productid") .datatextfield("text") .datavaluefield("value") .autobind(false) //.text(model.productid == 0 ? " " : model.productname) .datasource(source => { source.read(read => { read.action("getmeansofproduction", "demandformeansofproduction", new { level = 3 }).data("onproductcomboboxadditionaldata"); }) .serverfiltering(false); }) .events(e => { e.change("productidchange"); e.databound("productiddatabound"); }) )
it looks like:
- whenever combobox not populated displays directly model value binded (id), if model empty -> thats '0' first case - , want wait data
- if set value and/or text of combobox empty looses binding model , after populated data doesn't know item should selected...
ideas of solution?
the solution turned out simple it's embarrassing...
i had switch text/value (name/id) pair text/text , there no 'blinking' or disappearance issue more.
turn:
@(html.kendo().combobox() .name("productid") .datatextfield("text") .datavaluefield("value")
into:
@(html.kendo().combobox() .name("productname") .datatextfield("text") .datavaluefield("text")
it causes additional work in controller @ least works.
i hope saves time have saved me some...
Comments
Post a Comment