Skip to content

Commit

Permalink
feat(ionic): add compareWith input for select type (#2277)
Browse files Browse the repository at this point in the history
  • Loading branch information
aitboudad committed Jun 1, 2020
1 parent 4003729 commit 7ef2b8e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
15 changes: 8 additions & 7 deletions src/bootstrap/src/lib/types/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { take } from 'rxjs/operators';
multiple
[class.custom-select]="to.customSelect"
[formControl]="formControl"
[compareWith]="to.compareWith || compareWith"
[compareWith]="to.compareWith"
[class.is-invalid]="showError"
[formlyAttributes]="field">
<ng-container *ngIf="to.options | formlySelectOptions:field | async as opts">
Expand Down Expand Up @@ -38,7 +38,7 @@ import { take } from 'rxjs/operators';
<ng-template #singleSelect>
<select class="form-control"
[formControl]="formControl"
[compareWith]="to.compareWith || compareWith"
[compareWith]="to.compareWith"
[class.custom-select]="to.customSelect"
[class.is-invalid]="showError"
[formlyAttributes]="field">
Expand Down Expand Up @@ -69,7 +69,12 @@ import { take } from 'rxjs/operators';
})
export class FormlyFieldSelect extends FieldType {
defaultOptions = {
templateOptions: { options: [] },
templateOptions: {
options: [],
compareWith(o1: any, o2: any) {
return o1 === o2;
},
},
};

// workaround for https://github.com/angular/angular/issues/10010
Expand Down Expand Up @@ -97,8 +102,4 @@ export class FormlyFieldSelect extends FieldType {
constructor(private ngZone: NgZone) {
super();
}

compareWith(o1: any, o2: any) {
return o1 === o2;
}
}
8 changes: 7 additions & 1 deletion src/ionic/src/lib/types/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { FieldType } from '@ngx-formly/core';
<ng-container *ngIf="to.options | formlySelectOptions:field | async; let selectOptions">
<ion-select
[formControl]="formControl"
[compareWith]="to.compareWith"
[ionFormlyAttributes]="field"
[multiple]="to.multiple"
[interface]="to.interface"
Expand All @@ -23,6 +24,11 @@ import { FieldType } from '@ngx-formly/core';
})
export class FormlyFieldSelect extends FieldType {
defaultOptions = {
templateOptions: { options: [] },
templateOptions: {
options: [],
compareWith(o1: any, o2: any) {
return o1 === o2;
},
},
};
}
13 changes: 7 additions & 6 deletions src/material/select/src/select.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { FieldType } from '@ngx-formly/material/form-field';
[placeholder]="to.placeholder"
[tabindex]="to.tabindex"
[required]="to.required"
[compareWith]="to.compareWith || compareWith"
[compareWith]="to.compareWith"
[multiple]="to.multiple"
(selectionChange)="change($event)"
[errorStateMatcher]="errorStateMatcher"
Expand All @@ -46,7 +46,12 @@ export class FormlyFieldSelect extends FieldType {
@ViewChild(MatSelect, <any> { static: true }) formFieldControl!: MatSelect;

defaultOptions = {
templateOptions: { options: [] },
templateOptions: {
options: [],
compareWith(o1: any, o2: any) {
return o1 === o2;
},
},
};

private selectAllValue!: { options: any, value: any[] };
Expand Down Expand Up @@ -77,10 +82,6 @@ export class FormlyFieldSelect extends FieldType {
}
}

compareWith(o1: any, o2: any) {
return o1 === o2;
}

_getAriaLabelledby() {
if (this.to.attributes && this.to.attributes['aria-labelledby']) {
return this.to.attributes['aria-labelledby'];
Expand Down

0 comments on commit 7ef2b8e

Please sign in to comment.