multiselect-react-dropdown icon indicating copy to clipboard operation
multiselect-react-dropdown copied to clipboard

Both option values is same but different id's

Open archalwar opened this issue 4 years ago • 4 comments

In multi select drop down with object having unique id but options values is same, if i select one item it is also selecting another item as well.

image

image

archalwar avatar May 24 '20 08:05 archalwar

If you look at isSelectedValue() in the source file, you can see that it is comparing the displayValue of the selected items which in this case, would cause them to be both selected. It should probably be comparing the keys instead, but I think it is unusual to have non-unique items in a dropdown. Unless you really need this behavior fixed, you should probably just continue on.

pmpurifoy avatar May 24 '20 10:05 pmpurifoy

Hi Pmpurifoy,

Thanks for your fast response.

Yes, i need it because as per my requirement, keys will be different and value will be same. So we need it.

Actually i to change isSelectedValue function as below, but still it is now working.

isSelectedValue(item) { const { isObject, displayValue } = this.props; const { selectedValues } = this.state; if (isObject) { return ( selectedValues.filter(i => i[displayValue] === item[displayValue]) .length > 0 ); } return selectedValues.filter(i => i === item).length > 0; }

to

isSelectedValue(item) { const { isObject, key } = this.props; const { selectedValues } = this.state; if (isObject) { return ( selectedValues.filter(i => i[key] === item[key]) .length > 0 ); } return selectedValues.filter(i => i === item).length > 0; }

And can you please let me where exactly i need to implement this changes, i tried to updated in node module folder as well and also same thing updated in component level as well, but nothing is worked.

Thanks in Advance

archalwar avatar May 24 '20 13:05 archalwar

Hi Pmpurifoy,

Thanks for your fast response.

Yes, i need it because as per my requirement, keys will be different and value will be same. So we need it.

Hi. Here (#21) you can find a workaround, which would help to display visually-same items in the same dropdown.

pushnovn avatar Sep 11 '20 07:09 pushnovn

I have the same use case where the display values are same for two or more different categories, which leads to a problem where, when I select on option of a category it automatically checks the same display value option of different category.

Is there a workaround where I can select same display values option of different category having different keys?

HiteshPsingh avatar Nov 01 '21 09:11 HiteshPsingh