Skip to content

Commit

Permalink
hotfix object dropdown compareWith
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-fabian committed Apr 21, 2024
1 parent cc8823a commit 9949562
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,15 @@ export class Person extends Entity {
street: 'test street'
}
}
]
],
default: {
city: 'test city',
formOfAddress: 'Mr.',
id: '42',
number: '123',
postcode: '12345',
street: 'test street'
}
})
addressDropdownObject!: Address[];

Expand Down
2 changes: 1 addition & 1 deletion projects/ngx-material-entity/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngx-material-entity",
"version": "16.1.2",
"version": "16.1.3",
"license": "MIT",
"keywords": [
"angular",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@
[name]="objectDropdownName"
[required]="metadata.required(entity)"
[disabled]="internalIsReadOnly"
[compareWith]="compareObjects"
[(ngModel)]="entity[propertyKey]"
(selectionChange)="emitChange()"
(opened)="selectSearchInput.focus()"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,14 +235,14 @@ export class NgxMatEntityInputComponent<EntityType extends BaseEntityType<Entity
* The currently selected object as a drop down value.
*/
get currentObjectDropdownValue(): DropdownValue<EntityType | undefined> | undefined {
return LodashUtilities.cloneDeep(this.objectDropdownValues ?? []).find(v => v.value === this.entity[this.propertyKey]);
return LodashUtilities.cloneDeep(this.objectDropdownValues ?? []).find(v => LodashUtilities.isEqual(v.value, this.entity[this.propertyKey]));
}
// eslint-disable-next-line jsdoc/require-returns
/**
* Whether or not the current object dropdown value should be shown in the dropdown.
*/
get shouldDisplayCurrentObjectDropdownValue(): boolean {
return !!this.currentObjectDropdownValue && !(!!this.filteredObjectDropdownValues.find(v => v.value === this.currentObjectDropdownValue?.value));
return !!this.currentObjectDropdownValue && !(!!this.filteredObjectDropdownValues.find(v => LodashUtilities.isEqual(v.value, this.currentObjectDropdownValue?.value)));
}

@ViewChild('addArrayItemDialog')
Expand Down Expand Up @@ -740,6 +740,16 @@ export class NgxMatEntityInputComponent<EntityType extends BaseEntityType<Entity
});
}

/**
* Checks if two objects are equal. Is needed for the dropdown.
* @param value1 - The first object to compare.
* @param value2 - The second object to compare.
* @returns Whether or not the objects are the same.
*/
compareObjects(value1?: EntityType, value2?: EntityType): boolean {
return LodashUtilities.isEqual(value1, value2);
}

/**
* Filters the dropdown values.
* @param searchInput - The search input to filter for.
Expand Down

0 comments on commit 9949562

Please sign in to comment.