Choices-js / Choices

A vanilla JS customisable select box/text input plugin ⚡️
https://choices-js.github.io/Choices/
MIT License
6.17k stars 607 forks source link

Bug fix for assignment of customProperties in the option template #1083

Closed AnomalousBit closed 1 month ago

AnomalousBit commented 1 year ago

Description

When providing a JSON encoded data-custom-properties attribute on the original <option> elements, attempting to access the dataset.customProperties later, inside of a Choices event would return an improperly encoded "[object Object]" string instead of the expected JSON object.

This PR fixes the option template attribute for data-custom-properties by using JSON.stringify() before attempting to covert customProperties into a string.

Several issues open around custom properties may be fixed by this PR.

Screenshots (if appropriate)

Types of changes

Checklist

tagliala commented 1 year ago

Should fix #1036

mtriff commented 1 year ago

Thanks for this! Can you add a unit test for this that would have failed previously but now passes with your change?

Xon commented 1 month ago

Thanks, I've implemented a more comprehensive fix as part of https://github.com/Choices-js/Choices/pull/1166