Skip to content
This repository was archived by the owner on Nov 13, 2024. It is now read-only.

Commit 444ef1a

Browse files
Albert GraciaAlbert Gracia
authored andcommitted
Fix selected option in select for json dataSrc
use compareWith option from the angular mat-slect component to be able to set the selected option when the option is an object
1 parent a450333 commit 444ef1a

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

projects/angular-material-formio/src/lib/components/select/select.component.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Component, OnInit } from '@angular/core';
22
import { MaterialComponent } from '../MaterialComponent';
33
import SelectComponent from 'formiojs/components/select/Select.js';
4+
import _ from 'lodash';
45
@Component({
56
selector: 'mat-formio-select',
67
template: `
@@ -20,6 +21,7 @@ import SelectComponent from 'formiojs/components/select/Select.js';
2021
[formControl]="control"
2122
[placeholder]="instance.component.placeholder"
2223
(selectionChange)="onChange()"
24+
[compareWith]="compareObjects"
2325
>
2426
<div class="mat-option">
2527
<input class="mat-input-element" placeholder="Type to search" (input)="onFilter($event.target.value)">
@@ -45,7 +47,7 @@ export class MaterialSelectComponent extends MaterialComponent implements OnInit
4547
selectOptions: Promise<any[]>;
4648
filteredOptions: Promise<any[]>;
4749
filteredOptionsLength: number;
48-
50+
4951
selectOptionsResolve: any;
5052

5153
setInstance(instance: any) {
@@ -71,6 +73,10 @@ export class MaterialSelectComponent extends MaterialComponent implements OnInit
7173
return filtered;
7274
})
7375
}
76+
77+
compareObjects(o1: any, o2: any): boolean {
78+
return _.isEqual(o1, o2);
79+
}
7480
}
7581
SelectComponent.MaterialComponent = MaterialSelectComponent;
7682

0 commit comments

Comments
 (0)