Hi!
We have a grid using popup editing from an ASP editor template - pretty simple. In the popup there is a cascading dropdown (company => department). Our primary goal this time was to auto-select the first entry in the department dropdown on databinding (could this maybe be added as an option of the dropdown in the future?), but when developing this we ran into some MVVM issues. The editor template is similar to this (with an added debug input box to illustrate MVVM behaviour):
To select the first element we tried (in javascript on document ready) using the select() function and the value() function, both of which visibly changed the value of the department dropdown but none of which changed the MVVM value (input value visibly, but more importantly grid ajax post on finishing editing):
We have a grid using popup editing from an ASP editor template - pretty simple. In the popup there is a cascading dropdown (company => department). Our primary goal this time was to auto-select the first entry in the department dropdown on databinding (could this maybe be added as an option of the dropdown in the future?), but when developing this we ran into some MVVM issues. The editor template is similar to this (with an added debug input box to illustrate MVVM behaviour):
@(Html.Kendo().DropDownList()
.Name(
"CompanyId"
)
.OptionLabel(
"Choose company"
)
.BindTo(MMHtmlHelperExtension.SelectListForCompany(Model !=
null
? Model.CompanyId :
null
))
.HtmlAttributes(
new
{ data_value_primitive =
"true"
})
)
@(Html.Kendo().DropDownList()
.Name(
"DepartmentId"
)
.OptionLabel(
"Choose department"
)
//We would like to remove this, but if this is removed and the dropdown contains only one element that element cannot be selected
.DataSource(source => source
.Read(read => read.Action(
"GetDepartmentsInCompany"
,
"EditorTemplates"
,
new
{area =
""
}))
.ServerFiltering(
true
))
.Enable(
false
)
.AutoBind(
false
)
.CascadeFrom(
"CompanyId"
)
.HtmlAttributes(
new
{ data_value_primitive =
"true"
})
)
<input id="inputToIllustrateMVVMBehaviour" data-bind="value: DepartmentId" />
To select the first element we tried (in javascript on document ready) using the select() function and the value() function, both of which visibly changed the value of the department dropdown but none of which changed the MVVM value (input value visibly, but more importantly grid ajax post on finishing editing):
departmentDropDownList
.dataSource
.bind(
"change"
,
function
(e) {
if
(departmentDropDownList.select() == 0) {
departmentDropDownList.select(1);
//Visibly changes the dropdown, but does not update the MVVM value
$(
"#DepartmentId_listbox"
).children().eq(1).click();
//Extremely hacky workaround that actually works. Selecting a department manually by clicking also works.
}
});
SO - the main questions:
- Is it possible to make the line "departmentDropDownList.select(1)" actually update the model? Can the update be forced in some way? Isn't that type of code really supposed to work out of the box?
- Is it possible to access the model of the popup directly? (instead of "dropdown.select(1)" do "popupModel.DepartmentId = theNewId" for example)
- Also - when adding/updating a grid using popup, the new line's columns "Company name" and "Deparment name" will be empty in this case until the post-back is done (the Id columns will work though). Is it possible to update the Company/Department name values when selecting values in each dropdown?
Best regards
Victor