I am following the Rendering Item Checkboxes documentation. But I'm running into a problem where when I try to reuse the form and existing controls, the multiselect displays the correct tags and the correct items are highlighted when you open it, but the checkbox inputs are not checked.
This is my HTML:
<
ng-container
*
ngSwitchCase
=
"'mulitselect'"
>
<
kendo-multiselect
[formControlName]="col.ControlName"
[data]="col.Extras.Data"
[textField]="col.Extras.TextField"
[valueField]="col.Extras.ValueField"
[valuePrimitive]="true"
[autoClose]="false">
<
ng-template
kendoMultiSelectItemTemplate
let-dataItem>
<
input
type
=
"checkbox"
class
=
"k-checkbox"
[checked]="isItemSelected(col.Extras.Data, dataItem, col.Extras.ValueField)">
<
label
class
=
"k-checkbox-label"
>{{ dataItem[col.Extras.TextField] }}</
label
>
</
ng-template
>
</
kendo-multiselect
>
</
ng-container
>
This is my isItemSelected method:
isItemSelected(data: any, dataItem: any, valueField) {
return
data.indexOf(item => item[valueField] === dataItem[valueField]) > -1;
}
This how I'm reusing the form, where control named Foo represents the multiselect:
showEditForm(record?: ITestInterface) {
this
.form.disable();
this
.form.reset(record);
// Patch in new value
if
(record) {
this
.form.get(
'Foo'
).setValue([1, 3]);
}
}
Attached is a screenshot demonstrating what I mean.