Choices icon indicating copy to clipboard operation
Choices copied to clipboard

Issue with customProperties via html data-custom-properties attribute

Open dennym opened this issue 5 months ago • 1 comments

For couple of days I am debugging why my customProperties are not searched properly. After debugging the lib, I found that my data-custom-properties are not properly instantiated as object.

Turns out that there is a boolean given to the assignCustomProperties function which I can not find reason for why it is there in the first place.

https://github.com/Choices-js/Choices/blob/d177c925c1d61eb933a8acbd658c58bab439aa5d/src/scripts/templates.ts#L35

This boolean is in all fn calls true but in case where my data is parsed it is set to false and my customProperties are not instantiated and therefor can not be searched:

https://github.com/Choices-js/Choices/blob/d177c925c1d61eb933a8acbd658c58bab439aa5d/src/scripts/templates.ts#L316

Whats the point of this boolean? Either there are data-custom-properties or not. If there are present, they are expected to be parsed right? Maybe its an oversight?

Would love some insight on this to further debug the issue. Best Denny

dennym avatar Aug 06 '25 07:08 dennym

The search feature doesn't actually use the data-custom-properties attribute on the rendered choices list. It loads them from the backing <select>'s and persists that as part of it's internal representation.

All the callbacks which pass this internal representation contain a parsed customProperties attribute

Xon avatar Aug 16 '25 17:08 Xon