[Bug]: New 'label' value is not displayed when second search returened the item with the same value but different label
Bug description
When I do the first search the return list is [{ label: 'x', value: 1 }].
When I do the second search the return list is [{ label: 'y', value: 1 }]. (eg. between searches someone updated the label in database).
But the TomSelect still displays the old label 'x'.
Expected behavior
I expect when new data comes all existing items should be updated, eg. 'x' should be replaced by 'y'.
Steps to reproduce
- Do the first search which should return
[{ label: 'x', value: 1 }] - Do the second search which should return
[{ label: 'y', value: 1 }] - You still see 'x' at the drop down, but it should be 'y'.
Additional context
- OS: Linux Mint
- Browser FF
- Version 130
- Device: Desktop
Please add the options you used.
All options are default except the load which just queries data from my localhost.
I have a very similar problem, and it might be enough to change this line from:
if( key === null || self.options.hasOwnProperty(key) ){
to:
if( key === null ){
Not sure if to remove || self.options.hasOwnProperty(key) can have side effects.
The description of the addOption method is tellig you, that the option doesn't get a refresh when nothing is changed. That is wrong, but not for the code....
https://github.com/orchidjs/tom-select/blob/2efbaab0abac19532bd38900f13b99762df601b4/src/tom-select.ts#L1626-L1637
self.options.hasOwnProperty(key) is checking, if the value exists on the option set. That's true. So we need here an additional check, of the label is changed an update then the label.
To do a permanent refresh needs much performance and local ressources. A better way is to deal with the updateOption method.
https://github.com/orchidjs/tom-select/blob/4522c18a0236061d6af19475e202a796f4a35a99/src/tom-select.ts#L1731-L1737
This should implemented as fallback to check in the addOption method. Maybe i have some time the next days and can test to implement a solution.