ix icon indicating copy to clipboard operation
ix copied to clipboard

Select component datakey for comparisons

Open JulianEvi opened this issue 1 year ago • 3 comments

What happened?

The select component seems to compare objects by reference, which is a problem if the value in the form control does not come from the collection that supplies the select. Other frameworks like Prime NG offer a "dataKey" property in order to prevent a deep compare, which enables the user to define the key used in such comparisons.

Due to this, the select field does not show an initial value if the form value came from a different backend call. Performing a mapping for every form control value that is used in a select is an overhead and can require additional refactoring in large existing applications. I solved it by wrapping the select component in another ControlValueAccessor, which handles the mapping.

What type of frontend frameware are you seeing the problem on?

Angular

Which version of iX do you use?

2.0.1

Code to produce this issue.

// product contains an object which is deep compared equal to one of the marketProducts, but has a different reference

<ix-select formControlName="product">
 <ix-select-item *ngFor="let item of marketProducts" label="{{ item.name }}" [value]="item">
 </ix-select-item>
</ix-select>

JulianEvi avatar Oct 09 '23 08:10 JulianEvi

Sounds valid can you please provide a link to the mantioned prime ng component which has this dataKey? Or your value accessor ?

danielleroux avatar Jan 26 '24 08:01 danielleroux

https://primeng.org/dropdown https://primeng.org/table

Those two components have the dataKey property.

JulianEvi avatar Feb 07 '24 08:02 JulianEvi

Internal ref [IX-891]

matthiashader avatar Feb 07 '24 12:02 matthiashader

See answer, regarding on value comparison here: https://github.com/siemens/ix/issues/1270#issuecomment-2151696893

matthiashader avatar Aug 20 '24 08:08 matthiashader