edcarroll / ng2-semantic-ui

Semantic UI Angular Integrations (no jQuery)
https://edcarroll.github.io/ng2-semantic-ui/
MIT License
615 stars 223 forks source link

feat(select) Support a compareWith property #297

Open Gimly opened 7 years ago

Gimly commented 7 years ago

I'm having an issue when using the sui-select component that the selected object that I'm binding to and the list of options are not coming from the same source (even though they are the same objects) and therefore are different instances of the same objects.

Angular fixes that by having a compareWith property that allows to pass a method that will be called to compare to objects for equality. See https://angular.io/api/forms/SelectControlValueAccessor#caveat-option-selection

It would be very useful to have that behavior reproduced in the sui-select component. Or maybe there is a workaround that I'm not aware of?

AlexSmirnov9107 commented 6 years ago

I've found out the bug with comparing options. You can fix it by editing already complied file node_modules/ng2-semantic-ui/dist/modules/select/classes/select-base.js change this return options.find(function (o) { return value === _this.valueGetter(o) }); to this return options.find(function (o) { return JSON.stringify(value) === JSON.stringify(_this.valueGetter(o)) });